1
Answer

How to refresh the DataSet after a data source update

Photo of xmail123

xmail123

20y
2.6k
1
After updating my data source using the DataAdapter.Update method I want to refresh the DataSet by repopulating it. There are apparently 2 approaches to accomplishing this. Approach 1 Refresh a dataset manually by calling an adapter's Fill method after calling its Update method. When I call the fill after the update the rows are appended to the data table. The data table is not over written as I expected. I have to do a Clear then the Fill. Is there something I am missing that is preventing the data table from being over written or is explicitly calling a Clear first the correct way to do this? Approach 2 Alternatively, you can configure the data adapter to automatically execute an SQL SELECT statement or stored procedure after performing the Update. In that case, the data adapter creates two SQL statements for the UpdateCommand and InsertCommand objects. The first statement executes the update, and the second statement is a SELECT statement designed to refresh the dataset. 1. I don't see a property or something in the data adapter to enable the automatically execute of an SQL SELECT statement or stored procedure after performing the Update. 2. In order for the second SELECT statement to execute, the data source must support batch queries as in SQL Server. How do I set that up?

Answers (1)

0
Photo of Santhosh Kumar Jayaraman
NA 9.9k 2.3m 12y
When You are deleting records,

You can write query as

delete table AU_Delete

or
delete from table au_Delete.

you have to use * only in select queries.

try this

 SqlConnection con = new SqlConnection("Data Source=APPLE;Initial Catalog=sam;Integrated Security=True");
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = con;
            con.Open();
            string str1 = "DELETE  AU_Delete";
            cmd.CommandText = str1;
            cmd.ExecuteNonQuery();
            con.Close();
          

0
Photo of Hemant Kumar
NA 3k 215.2k 12y
Mohammed Shamsheer,

you can't write '*' for the delete Statements

string Query="delete from AU_DELETE";
0
Photo of Naresh Avari
NA 811 1.6m 12y
Hi,

Remove '*' from your SQL Query and use

string str1 = "DELETE FROM AU_Delete";

You don't need to specify '*' for DELETE statement.