How to assign a value to a sql 'smalldatetime' data?

C

Chi Tang

Hi,

The following code shows that I try to pass a 'smalldatetime' data to the
'Today_Date' column when I add a new row to a table. I use the
'DateTimeFormatInfo' object to get the today date but did not know how to
convert to a sql 'smalldatetime'. Thanks for help.

DataSet ds = new DataSet("MyTable");

adapter.Fill(ds, "MyTable");

DataTable tbl = ds.Tables["MyTable];


DataRow row = tbl.NewRow();

row["Today_Date"] = ?; // this column data is a smalldatetime in sql

tbl.Rows.Add(row);
 
S

Stephen Muecke

Chi,

= Data.Today ? (or better, set the
MyTable.Columns("Today_Date").DefaultValue = Date.Today are you create the
table)
Having said that, why not just set the default value of your column in the
underlying database (using GetDate())
Then when you insert a new record into the database, don't set a value for
that column. You than won't have any possible errors caused if the date/time
settings on individual users computers are set incorrectly

Stephen
 

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