Insert Current Time of SQL server to database thr ASP.net

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a datetime field in table.

I want to insert the current time of database server to the table thr
ASP.NET (C#).

I have dataset to do the insert:

DataSet1.TableNameRow rowNew =
(DataSet1.TableNameRow)DataSet1.TableName.NewRow();
rowNew.DateTimeField = System.DateTime.Now;
(rest of the code..)

I would like to ask in the second line of the code, I can insert the current
time of the web server to the DateTimeField,
However if I want the time refer to the current time of the SQL server, i.e
the GETDATE() of MS SQL , what should I write?

I can't type

rowNew.DateTimeField = "GETDATE()";

Thanks for any help.
 
The Dataset is not meant to be used to update in this way. First of all, the
dataset don't have a clue what SQL Server is, therefore, GETDATE() will not
work. Secondly, this is not the most effecient way to do an update.
Insert this date using the SqlConnection and SqlCommand objects while
constructing your sql string.
 
The Dataset is not meant to be used to update in this way. First of all, the
dataset don't have a clue what SQL Server is, therefore, GETDATE() will not
work. Secondly, this is not the most effecient way to do an update.
Insert this date using the SqlConnection and SqlCommand objects while
constructing your sql string.

You cannot directly access SQL server batches in an ASP.NET script.

You must interface to SQL server through ADO.NET, which provides
classes, like SqlConnection and SqlCommand that provide access to the
data server.

Look at some of the examples describing server-side data access in
the ASP.NET examples:

http://samples.gotdotnet.com/quickstart/aspplus/


-- ipgrunt
 
Back
Top