VobiaGoTpab
New Member
How do you insert the Classic ASP value of "now()" into a timestamp field in asp.net? Here is my code in question. I also am having trouble inserting the value of "n" (my querystring), I am getting the value but i can't insert it. These are simple questions I realize but my ASP.NET book doesn't have anything in it that explains this.<BR><BR><%@Page Language= VB %><BR><%@ Import Namespace="System.Data.SqlClient"%><BR> <Script Runat=Server><BR> Sub Page_Load<BR> Dim n As string<BR> n = Request.Querystring("n")<BR> Dim conPrimedia As SqlConnection<BR> Dim strInsert As String<BR> Dim cmdInsert As SqlCommand<BR> conPrimedia = New SqlConnection( "Server=sqlmain;UID=sa;PWD=;database=News" )<BR> strInsert = "Insert Into html ( ID , BroadcastName, html, timestamp) VALUES ( n, 'PB', 'Y', 'now()' )"<BR> cmdInsert = New SqlCommand( strInsert, conPrimedia )<BR> conPrimedia.Open()<BR> cmdInsert.ExecuteNonQuery()<BR> conPrimedia.Close()<BR> Response.Write(n)<BR> Response.Write( "count.jpg" )<BR> end sub<BR></script><BR><BR>Thanks.what type is your ID field? I am assuming that it is numeric, so you will have to use CTYPE to cast the variable n.ID field is an int. Timestamp is a DateTime field in MSSQL 2000right, so you cant stick a string (which the request.querystring returns) ino an int field.I see your point, but the ID field is actually a varchar, just checked it again. The error I'm getting isn't a type mismatch or anything like that It's more of a variable declaration problem. I'm not familar with how you name and insert a variable in ASP.NET.Here is the code again: My question is what do I name the variable going into the database string. I tried @n, ' & n & ', and various others.<BR><BR><%@Page Language= VB %><BR><%@ Import Namespace="System.Data.SqlClient"%><BR> <Script Runat=Server><BR> Sub Page_Load<BR> Dim n As string<BR> n = Request.Querystring("n")<BR> Dim conPrimedia As SqlConnection<BR> Dim strInsert As String<BR> Dim cmdInsert As SqlCommand<BR> conPrimedia = New SqlConnection( "Server=;UID=;PWD=;database=" )<BR> strInsert = "Insert Into html ( ID , BroadcastName, html, timestamp) VALUES ( n, 'PB TP NN OP lists 3/5/02', 'Y', now() )"<BR> cmdInsert = New SqlCommand( strInsert, conPrimedia )<BR> conPrimedia.Open()<BR> cmdInsert.ExecuteNonQuery()<BR> conPrimedia.Close()<BR> Response.Write(n)<BR> Response.Write( "count.jpg" )<BR> end sub<BR></script><BR><BR>thanksWhen I try @n I get a "Character is not valid" error. I've tried everything i can think of.I GOT IT, WOW. All it was is '" & n & "', i had the incorrect syntax.