Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
CommandBuilder doesn't help
Message
From
09/11/2007 12:35:11
 
General information
Forum:
ASP.NET
Category:
Databases
Miscellaneous
Thread ID:
01267891
Message ID:
01267986
Views:
7
Patrick,

Using the CommandBuilder is more of a crutch than anything else. It's a bad idea, IMHO.

Whether you generate the SQL commands yourself, or you use a Stored Proc, your best bet is to have a generic method to auto-generate this stuff for you. Basically, it would just iterate through the columns in your table and generate either a SQL command text or Parameters to use in your Stored Proc call. Maybe something like this for generating SP parms, just to give you an idea and get you started:
public void SetParameters(SqlCommand sc, DataTable dt, DataRow row, string PKName)
{
  sc.Parameters.Clear();
  for (int i=0; i < dt.Columns.Count; i++)
  {
    if (row[i] != DBNull.Value)
      sc.Parameters.Add("@" + dt.Columns[i].ColumnName, row[i]);
  }

  sc.Parameters["@" + PKName].Direction = ParameterDirection.InputOutput;
}
Hope this helps ...

~~Bonnie



>Hi to everybody
>The restriction of the command builder of working only for Selects without join is for me a no go. Building all update etc commands each time on foot as well.
>
>Did anybody build something to retrieve the CommandText of the SQL Object and to build the other command objects in a more intelligent way than the command builder does?
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Reply
Map
View

Click here to load this message in the networking platform