adspace


Write Code for DataSet,Datareader,and by deleting the button
gridview should be empty?

Answer Posted / Ritesh Kumar Siddharth

Here's a simple example of using DataSet and DataReader with ADO.NET in C#:nnFirst, create a function to fill a DataSet:n```csharpnpublic static DataSet FillDataSet(string connectionString, string query)n{n SqlConnection connection = new SqlConnection(connectionString);n SqlCommand command = new SqlCommand(query, connection);n DataSet dataSet = new DataSet();n SqlDataAdapter adapter = new SqlDataAdapter(command);n adapter.Fill(dataSet);n return dataSet;n}n```nNext, create a function to fill a DataReader:n```csharpnpublic static void FillDataReader(string connectionString, string query, Action<SqlDataReader> action)n{n SqlConnection connection = new SqlConnection(connectionString);n SqlCommand command = new SqlCommand(query, connection);n connection.Open();n SqlDataReader reader = command.ExecuteReader();n action(reader);n reader.Close();n}n```nFinally, to empty a GridView after deleting a row, simply bind an empty DataTable to the GridView's DataSource property:n```csharpngridView1.DataSource = null;ngridView1.DataSource = new DataTable();ngridView1.DataBind();n```

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Write the .net syntax for 'while loop'?

1143