I just tried to create a simple ASP.NET application to add record to the SQL
Server database. However, it has run time error on Line 88:
objCommand.ExecuteNonQuery()
Any ideas?? Please help!! Thanks!!
Sub AddNewRecord()
Dim objConnection As SqlConnection
Dim strConnection As String = "Data Source=20.11.12.91;Network
Library=DBMSSOCN;Initial Catalog=testtable;User ID=sa;Password=iw;"
objConnection = New SqlConnection(strConnection)
Dim objCommand As SqlCommand
Dim strSQLQuery As String
strSQLQuery = "INSERT INTO Test " _
& "(FirstName, LastName, SerialNumber) " _
& "VALUES (@TextValue, @TextValue, @TextValue)"
objCommand = New SqlCommand(strSQLQuery, objConnection)
objCommand.Parameters.Add(New SqlParameter("@TextValue", SqlDbType.Char,
255))
objCommand.Parameters.Add(New SqlParameter("@TextValue", SqlDbType.Char,
255))
objCommand.Parameters.Add(New SqlParameter("@TextValue", SqlDbType.Char,
255))
objCommand.Parameters("@TextValue").Value = CStr(TextBox1.Text)
objCommand.Parameters("@TextValue").Value = CStr(TextBox2.Text)
objCommand.Parameters("@TextValue").Value = CStr(TextBox4.Text)
objConnection.Open()
objCommand.ExecuteNonQuery()
objConnection.Close()
End Sub
Runtime error:
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: ?? ??
'@TextValue'?(?) ?? ???????. ?? ??? ?? ?? ?? ?? ?? ???? ??? ???? ???.
Source Error:
Line 86: ' Open the connection, execute the command, and close the
connection.
Line 87: objConnection.Open()
Line 88: objCommand.ExecuteNonQuery()
Line 89: objConnection.Close()
Line 90: 1 4250
& "VALUES (@TextValue, @TextValue, @TextValue)"
should be:
& "VALUES ('@TextValue', '@TextValue', '@TextValue')"
notice the single-quotes
Hope this helps...
"Matthew Louden" <ma*******@hotmail.com> wrote in message
news:uP*************@TK2MSFTNGP10.phx.gbl... I just tried to create a simple ASP.NET application to add record to the
SQL Server database. However, it has run time error on Line 88: objCommand.ExecuteNonQuery()
Any ideas?? Please help!! Thanks!!
Sub AddNewRecord() Dim objConnection As SqlConnection Dim strConnection As String = "Data Source=20.11.12.91;Network Library=DBMSSOCN;Initial Catalog=testtable;User ID=sa;Password=iw;" objConnection = New SqlConnection(strConnection) Dim objCommand As SqlCommand Dim strSQLQuery As String strSQLQuery = "INSERT INTO Test " _ & "(FirstName, LastName, SerialNumber) " _ & "VALUES (@TextValue, @TextValue, @TextValue)" objCommand = New SqlCommand(strSQLQuery, objConnection) objCommand.Parameters.Add(New SqlParameter("@TextValue", SqlDbType.Char, 255)) objCommand.Parameters.Add(New SqlParameter("@TextValue", SqlDbType.Char, 255)) objCommand.Parameters.Add(New SqlParameter("@TextValue", SqlDbType.Char, 255)) objCommand.Parameters("@TextValue").Value = CStr(TextBox1.Text) objCommand.Parameters("@TextValue").Value = CStr(TextBox2.Text) objCommand.Parameters("@TextValue").Value = CStr(TextBox4.Text) objConnection.Open() objCommand.ExecuteNonQuery() objConnection.Close() End Sub
Runtime error:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: ?? ?? '@TextValue'?(?) ?? ???????. ?? ??? ?? ?? ?? ?? ?? ???? ??? ???? ???.
Source Error:
Line 86: ' Open the connection, execute the command, and close the
connection. Line 87: objConnection.Open() Line 88: objCommand.ExecuteNonQuery() Line 89: objConnection.Close() Line 90:
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Barry Young |
last post by:
I am using the following code to insert a row in an Oracle Database.
strConnection = "Provider=OraOLEDB.Oracle;Data Source=MYDATABASE;User
Id=SYSTEM;Password=******"
Dim strMessage As String
...
|
by: Aaron_TekRecycle.com |
last post by:
this runs perfectly as a .vbs but I'd like to convert it to an ASP... any
ideas?
Response.Buffer = True
Dim objConnection, objCommand, objRecordSet
Dim oPrinterName, oServerName
Const...
|
by: sunmiester |
last post by:
I have an ASP page that retrieves user info. The page runs fine on XP
Pro IIS 5.1, however, when i try to run it from a server running W2k
Server SP4 or W2K3, it breaks and i get the following...
|
by: abdul haleem |
last post by:
hiye guys, can anyone tell me whats wrong with this piece
of code? to my knowledge, its looks and seems fine. i'm
very puzzle by this error.
i get this error msg
"Operation must use an updateable...
|
by: Joe |
last post by:
Hello All,
I am trying to insert a record in the MS Access DB and for some reason I cannot get rid of error message,
System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement.
...
|
by: Joe |
last post by:
Hello All,
I am trying to insert a record in the MS Access DB and for some reason I cannot get rid of error message,
System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement.
...
|
by: darrel |
last post by:
I'm trying to delete a record in a table:
Dim strConnect As String =
System.Configuration.ConfigurationSettings.AppSettings("myConnectionString")
Dim strChk = "DELETE FROM we_admin_users WHERE...
|
by: Jim in Arizona |
last post by:
I have a gridview that's being populated from an access db query. The
problem I'm having is that the date/time fields in access that are
populating the gridview are showing both date and time, when...
|
by: Jim |
last post by:
I'm trying to take the data from strSQL below and "append / insert" that
into the Access database. The problem is: although the listbox displays
correctly, the Access table gets the first record...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |