PC Review


Reply
Thread Tools Rate Thread

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

 
 
Chi Tang
Guest
Posts: n/a
 
      17th Jul 2003
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);




 
Reply With Quote
 
 
 
 
Stephen Muecke
Guest
Posts: n/a
 
      18th Jul 2003
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

"Chi Tang" <(E-Mail Removed)> wrote in message
news:Op$(E-Mail Removed)...
> 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);
>
>
>
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SmallDateTime Smokey Grindel Microsoft ADO .NET 7 14th Feb 2008 10:04 PM
Detecting database column data type of smalldatetime vs. datetime? Jen Microsoft ADO .NET 3 8th Aug 2007 08:44 AM
SqlDbType.SmallDateTime =?Utf-8?B?TWFyYw==?= Microsoft ADO .NET 1 16th May 2005 08:52 PM
conversation of char data type to smalldatetime Atilla Gunes Microsoft C# .NET 1 6th Apr 2005 04:06 PM
SmallDateTime Jim Heavey Microsoft ADO .NET 3 29th Dec 2003 04:46 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:55 PM.