I got this extract from msdn
MSDN COMMAND BUILDER CLASS
. Would it be alright to use in ASP.NET to quickly insert, or update, or delete from a table or will be inefficient?!
public static DataSet SelectSqlRows(string connectionString, string queryString, string tableName)
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = new SqlCommand(queryString, connection);
SqlCommandBuilder builder = new SqlCommandBuilder(adapter);
connection.Open();
DataSet dataSet = new DataSet();
adapter.Fill(dataSet, tableName);
//code to modify data in DataSet here
builder.GetUpdateCommand();
//Without the SqlCommandBuilder this line would fail
adapter.Update(dataSet, tableName);
return dataSet;
}
}
There are no issues with your code regarding efficiency. One suggestion is to use stored procedures or parameterised queries rather than are executing your query string directly which will help prevent SQL Injection.
Reference:
http://www.dotnetperls.com/sqlparameter