469,612 Members | 1,517 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,612 developers. It's quick & easy.

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

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.

Nov 19 '05 #1
3 3458
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.

"j@son.c" wrote:
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.

Nov 19 '05 #2
On 19 Feb 2005, "=?Utf-8?B?VGFtcGEgLk5FVCBLb2Rlcg==?="
<Ta***********@discussions.microsoft.com> postulated in
news:65**********************************@microsof t.com:
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.

"j@son.c" wrote:
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.


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

Nov 19 '05 #3
Typically, you wouldn't do this in .NET. You'd do it in your database.
Just set the default value for your datetime column to getdate()

Then, just don't reference the column in your insert statement.

If you are using stored procedures, you'd just update the column
with getdate() on update calls.

--
2005 Microsoft MVP C#
Robbe Morris
http://www.robbemorris.com
http://www.mastervb.net/home/ng/foru...t10017013.aspx
http://www.eggheadcafe.com/articles/..._generator.asp

<j@son.c> wrote in message news:eS**************@tk2msftngp13.phx.gbl...
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.

Nov 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by shank | last post: by
8 posts views Thread by Josué Maldonado | last post: by
46 posts views Thread by dunleav1 | last post: by
9 posts views Thread by David Eades | last post: by
6 posts views Thread by rn5a | last post: by
5 posts views Thread by =?Utf-8?B?bXBhaW5l?= | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.