TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
mohit gupta
NA
145
59.6k
Error updating table in data grid view in c#
Dec 13 2013 4:30 AM
(1)Update requires a valid UpdateCommand when passed DataRow collection with modified rows.OR
(2) Dynamic SQL generation is not supported against multiple base tables.
I using join query and updating.but error is display above.
my code is.....
public partial class Form5 : Form
{
string con = "Data Source=ITSW2;Initial Catalog=Export;Integrated Security=True";
private SqlConnection connection;
private SqlCommand command;
private SqlDataAdapter adapter;
private SqlCommandBuilder builder;
private DataSet ds;
private DataTable userTable;
public Form5()
{
InitializeComponent();
}
private void btnload_Click(object sender, EventArgs e)
{
string query = "select A.partno, A.BoxNo,A.partdesc,A.partypartno,A.boxqty,A.stdwt,A.netwt,A.grosswt from BoxPacking A join Packing B on A.DespLotId=B.DespLotId where B.PackingId=1525"
connection = new SqlConnection(con);
connection.Open();
command = new SqlCommand(query, connection);
adapter = new SqlDataAdapter(command);
//builder= new SqlCommandBuilder(adapter);
ds = new DataSet();
adapter.Fill(ds, "NewTable");
userTable = ds.Tables["NewTable"];
connection.Close();
dataGridView1.DataSource = userTable;
dataGridView1.ReadOnly = true;
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
edit.Enabled = true;
btnupdate.Enabled = true;
}
private void btnupdate_Click(object sender, EventArgs e)
{
try
{
connection.Open();
adapter.Update(userTable);
dataGridView1.ReadOnly = true;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
btnupdate.Enabled = true;
}
finally
{
edit.Enabled = true;
btnload.Enabled = true;
connection.Close();
}
}
private void edit_Click(object sender, EventArgs e)
{
try
{
dataGridView1.ReadOnly = false;
edit.Enabled = false;
btnupdate.Enabled = true;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
}
Reply
Answers (
8
)
Call c# function for retrieve data from javascript passing j
how to speech Record Fetching ?..