Reputation: 14417
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;
}
}
Upvotes: 2
Views: 1918
Reputation: 70728
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
Upvotes: 2
Reputation: 63956
It would be as efficient as the underlying SQL statement that you execute is.
Upvotes: 0