onez

onez

  • NA
  • 73
  • 0

SQL insert statement w/ parameters

Dec 13 2005 10:25 PM
When inserting values into a database, I have to have many insert statments, IF the fields are in nonsequential order.  However, if all the fields (columns) in the database are next to each other I can insert all values in the same OleCommand.  Is there an easier way to do this?  Notice I also have to put 'company.symbol' in the statement itself.  If I use it as a parameter then the paramters get mixed up and inserted into wrong field.



"UPDATE " + company.industry +

" SET " +

" NumFound = @NumFound " +

" WHERE Symbol = '" + company.symbol + "'";

myOleDbCommand.Parameters.Add("@NumFound", OleDbType.Boolean);

myOleDbCommand.Parameters["@NumFound"].Value = found;

myOleDbCommand.CommandText = updateARfoundString;

Console.WriteLine("OK: " + myOleDbCommand.ExecuteNonQuery() + " record added");

string updateReportLinkString =

"UPDATE " + company.industry +

" SET " +

" ReportLink = @ReportLink " +

" WHERE Symbol = '" + company.symbol + "'";

myOleDbCommand.Parameters.Clear();

myOleDbCommand.Parameters.Add("@ReportLink", OleDbType.Char);

myOleDbCommand.Parameters["@ReportLink"].Value = "#" + WWWLink + "#";