read/write datetime from/to C#  
Author Message
worldhello





PostPosted: Visual C# General, read/write datetime from/to C# Top

Hello everybody

How to read/write 'datetime' type from SQL Server to C#


Thanks




Visual C#7  
 
 
boban.s





PostPosted: Visual C# General, read/write datetime from/to C# Top

The best way is to send it or read it as DateTime value type:
When you insert value in some statement or as parameter in stored procedure here is an example:
cmd.Paramateres.Add("@MyDate", SqlDbType.DateTime).Value = dateVariable;

when reading from SqlDataReader then you will read this way:
dateVariable = myDataReader.GetDateTime(myDataReader.GetOrdinal("MyDate"));