How can I retrieve data from a Table in a SqlServer, populate a DataGrid, modify the data in the DataGrid and UpDate the Data of the table?
I tried this:
MyDataAdapter = new SqlDataAdapter("SELECT * FROM MyTable", MyConnection); //Public DataAdapter
SqlCommand MyUpDateCommand = new SqlCommand("UPDATE MyTable SET Column1 = @Column1, Column2 = @Column2", MyConnection);
MyCommand.Parameters.Add("@Column1",System.Data.SqlDbType.Bit, 1, "Column1");
MyCommand.Parameters.Add("@Column2",System.Data.SqlDbType.VarChar, 50, "Column2");
MyDataAdapter.UpdateCommand=MyUpDateCommand;
MyDataSet = new DataSet(); //Public DataSet
MyDataAdapter.Fill(MyDataSet, "MyTable");
MyDataGrid.SetDataBinding(MyDataSet, "MyTable");//Also I tried MyDataGrid.DataSource = MyDataSet.Tables["MyTable"];
//Method of de Save Button
SaveButton_Click(object sender, System.EventArgs e)
{
MyDataAdapter.Update(MyDataSet, "MyTable");
}
The above it doesn't work.
What am I missing?
Could Any1 help me?
Thanx in advance.