473,394 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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 3638
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Jack | last post by:
I have a text file of data in a file (add2db.txt) where the entries are already entered on separate lines in the following form: INSERT INTO `reviews` VALUES("", "Tony's", "Lunch", "Great...
10
by: shank | last post by:
I have a recordset that contains multiple records of product a user is purchasing. For clarity, I converted the recordset fields to variables. I need to take that entire recordset and insert it...
18
by: Robin Lawrie | last post by:
Hi again, another problem! I've moved from an Access database to SQL server and am now having trouble inserting dates and times into seperate fields. I'm using ASP and the code below to get the...
8
by: Josué Maldonado | last post by:
Hello List, I'm importing some data from Foxpro to Postgres, there is atable wich contains aprox 4.8 million rows and it size about 830MB. I uploaded it to Postgres using dbf2pg and worked fine,...
46
by: dunleav1 | last post by:
I have a process that does inserts that runs 50% slower that Oracle and Mssql. Queries normally take 50% slower than normal. DB2, Oracle, Mssql all are configured on same os, same disk array...
9
by: David Eades | last post by:
Hi all Complete newbie here, so apologies if this is the wrong forum. I've been asked to use mysql and asp to make a simple bidding system (rather like a simple ebay), whereby users can use a...
6
by: rn5a | last post by:
During registration, users are supposed to enter the following details: First Name, Last Name, EMail, UserName, Password, Confirm Password, Address, City, State, Country, Zip & Phone Number. I am...
10
by: MLH | last post by:
Suppose, in a multi-user environment, you have append query SQL in a VBA procedure that looks like INSERT INTO MyTable... and the next line reads MyVar=DMax("","MyTable... You can never be...
5
by: =?Utf-8?B?bXBhaW5l?= | last post by:
Hello, I am completely lost as to why I can't update a DropDownList inside a DetailsView after I perform an insert into an object datasource. I tried to simply it down to the core demostration:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.