dates in dataadapter sql

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi

I am looking for some examples of how to use dates in sql statement in the
dataadapter context.

Thanks

Regards
 
Do you mean the format of the date in the SQL string?

The easy way is to not worry about typing the full SQL string. Use Command
objects with Parameters for each field.

SqlCommand cmdUpdate = new SqlCommand();
cmdUpdate.Connection = myConnection;
cmdUpdate.CommandText = new SqlCommand("UPDATE titles SET "
+ "title = @title"+ ", "
+ "type = @type"+ ", "
+ "pub_id = @pub_id"+ ", "
+ "price = @Price"+ ", "
+ "advance = @Advance"+ ", "
+ "royalty = @royalty"+ ", "
+ "ytd_sales = @ytd_sales"+ ", "
+ "notes = @Notes"+ ", "
+ "pubdate = @pubdate"+ " WHERE title_id = @title_id");

.... add first parameters here...
SqlParameter prm9 = new SqlParameter("@pubdate" , SqlDbType.DateTime);
prm9.SourceColumn = "pubdate";
cmdUpdate.Parameters.Add(prm9);

Now make this the UpdateCommand on your DataAdapter.

Michael Lang, MCSD
Take a look at my open source database project code generator...
http://sourceforge.net/projects/dbobjecter
 
Back
Top