dates in dataadapter sql

J

John

Hi

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

Thanks

Regards
 
M

Michael Lang

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top