473,795 Members | 3,122 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Run time error on: objCommand.Exec uteNonQuery()

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.Exec uteNonQuery()

Any ideas?? Please help!! Thanks!!

Sub AddNewRecord()
Dim objConnection As SqlConnection
Dim strConnection As String = "Data Source=20.11.12 .91;Network
Library=DBMSSOC N;Initial Catalog=testtab le;User ID=sa;Password= iw;"
objConnection = New SqlConnection(s trConnection)
Dim objCommand As SqlCommand
Dim strSQLQuery As String
strSQLQuery = "INSERT INTO Test " _
& "(FirstName , LastName, SerialNumber) " _
& "VALUES (@TextValue, @TextValue, @TextValue)"
objCommand = New SqlCommand(strS QLQuery, objConnection)
objCommand.Para meters.Add(New SqlParameter("@ TextValue", SqlDbType.Char,
255))
objCommand.Para meters.Add(New SqlParameter("@ TextValue", SqlDbType.Char,
255))
objCommand.Para meters.Add(New SqlParameter("@ TextValue", SqlDbType.Char,
255))
objCommand.Para meters("@TextVa lue").Value = CStr(TextBox1.T ext)
objCommand.Para meters("@TextVa lue").Value = CStr(TextBox2.T ext)
objCommand.Para meters("@TextVa lue").Value = CStr(TextBox4.T ext)
objConnection.O pen()
objCommand.Exec uteNonQuery()
objConnection.C lose()
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.Sql Client.SqlExcep tion: ?? ??
'@TextValue'?(? ) ?? ???????. ?? ??? ?? ?? ?? ?? ?? ???? ??? ???? ???.

Source Error:

Line 86: ' Open the connection, execute the command, and close the
connection.
Line 87: objConnection.O pen()
Line 88: objCommand.Exec uteNonQuery()
Line 89: objConnection.C lose()
Line 90:
Nov 17 '05 #1
1 4274
& "VALUES (@TextValue, @TextValue, @TextValue)"

should be:

& "VALUES ('@TextValue', '@TextValue', '@TextValue')"

notice the single-quotes

Hope this helps...

"Matthew Louden" <ma*******@hotm ail.com> wrote in message
news:uP******** *****@TK2MSFTNG P10.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.Exec uteNonQuery()

Any ideas?? Please help!! Thanks!!

Sub AddNewRecord()
Dim objConnection As SqlConnection
Dim strConnection As String = "Data Source=20.11.12 .91;Network
Library=DBMSSOC N;Initial Catalog=testtab le;User ID=sa;Password= iw;"
objConnection = New SqlConnection(s trConnection)
Dim objCommand As SqlCommand
Dim strSQLQuery As String
strSQLQuery = "INSERT INTO Test " _
& "(FirstName , LastName, SerialNumber) " _
& "VALUES (@TextValue, @TextValue, @TextValue)"
objCommand = New SqlCommand(strS QLQuery, objConnection)
objCommand.Para meters.Add(New SqlParameter("@ TextValue", SqlDbType.Char,
255))
objCommand.Para meters.Add(New SqlParameter("@ TextValue", SqlDbType.Char,
255))
objCommand.Para meters.Add(New SqlParameter("@ TextValue", SqlDbType.Char,
255))
objCommand.Para meters("@TextVa lue").Value = CStr(TextBox1.T ext)
objCommand.Para meters("@TextVa lue").Value = CStr(TextBox2.T ext)
objCommand.Para meters("@TextVa lue").Value = CStr(TextBox4.T ext)
objConnection.O pen()
objCommand.Exec uteNonQuery()
objConnection.C lose()
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.Sql Client.SqlExcep tion: ?? ??
'@TextValue'?(? ) ?? ???????. ?? ??? ?? ?? ?? ?? ?? ???? ??? ???? ???.

Source Error:

Line 86: ' Open the connection, execute the command, and close the connection.
Line 87: objConnection.O pen()
Line 88: objCommand.Exec uteNonQuery()
Line 89: objConnection.C lose()
Line 90:

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
12647
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 Dim objConnection As New OleDb.OleDbConnection(strConnection) Dim objCommand As OleDb.OleDbCommand
0
5751
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 ADS_SCOPE_SUBTREE = 2 Set objConnection = CreateObject("ADODB.Connection") Set objCommand = CreateObject("ADODB.Command")
0
2151
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 error: Error Type: Microsoft VBScript runtime (0x800A000D) Type mismatch Code:
0
1293
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 query." anyone knows what it means? below is the code
2
2853
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. And the line it shows in red is cmd.ExecuteNonQuery()
1
5427
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. And the line it shows in red is cmd.ExecuteNonQuery()
2
2067
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 UserID='" & myUserID & "'" Dim objConnect As New System.Data.OleDb.OleDbConnection(strConnect) objConnect.Open() Dim objCommand As New System.Data.OleDb.OleDbCommand(strChk, objConnect) objCommand.ExecuteNonQuery()
3
3317
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 the field should only be showing one or the other (date or time). Even on the back end of the database where the column properties are, I have chosen the smallest date/time formats. When the aspx page runs, it shows the date and time (ie:in a...
1
3556
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 inserted to the table multiple times - as many rows as there are in the source table. Obviously the Access parameters aren't getting updated properly. I've tried putting the .parameters.Add outside the for - next loop. No joy. Also, if...
0
9672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10439
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10165
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9043
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7541
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6783
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.