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

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.
 
G

Guest

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.
 
I

IPGrunt

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
 
R

Robbe Morris [C# MVP]

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top