473,841 Members | 1,792 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Syntax error in INSERT INTO statement.

2 New Member
I got the following 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.Ole Db.OleDbExcepti on: Syntax error in INSERT INTO statement.

The source error is : MYcmd.ExecuteNo nQuery()

Here is my Code: (Help me.....Thanks)
'============== =============== ===========
Function addTeacherRecor d(ByVal lName As String, ByVal fName As String)




' Change Data Source to the location of Northwind.mdb on your local
Dim sConStr As String = "PROVIDER=Micro soft.Jet.OLEDB. 4.0;Data " _
& "Source=" & Server.MapPath( "~/App_Data/students.mdb")


Dim password As String = generatePasswor d()
Dim userStatus As String

If statusList.Sele ctedIndex = 0 Then
userStatus = "Yes"
Else
userStatus = "No"
End If

Dim userProfile As String

If profileList.Sel ectedIndex = 0 Then
userProfile = "User"
Else
userProfile = "Admin"
End If

Dim user_name = fName + lName(0)



Dim mySQL As String = "INSERT INTO teachersTable (FirstName, LastName, UserName, Password, UserStatus,acti ve) VALUES ('" & fName & "','" & lName & "','" & user_name & "','" & password & "','" & userProfile & "','" & 1 & "')"


Dim MyConn As New Data.OleDb.OleD bConnection(sCo nStr)


MyConn.Open()
Dim MYcmd As New Data.OleDb.OleD bCommand(mySQL, MyConn)
MYcmd.ExecuteNo nQuery()
MyConn.Close()


newsLable1.Visi ble = True
newsLable2.Visi ble = True
newsLable2.Text = "הזנת הנתונים עבור " & fName & " " & lName & " הסתיימה בהצלחה."
userPassword1.V isible = True
userPassword1.V isible = True
userPassword1.T ext = password
UserName2.Text = fName + lName(0)


Return 0
End Function
Mar 19 '07 #1
2 3186
clain
79 New Member
Dear..

this is a simple error...

Dim mySQL As String = "INSERT INTO teachersTable (FirstName, LastName, UserName, Password, UserStatus,acti ve) VALUES ('" & fName & "','" & lName & "','" & user_name & "','" & password & "','" & userProfile & "','" & 1 & "')"

here is where you went wrong ..

you can change it to

Dim mySQL As String = "INSERT INTO teachersTable (FirstName, LastName, UserName, Password, UserStatus,acti ve) VALUES ('" & fName & "','" & lName & "','" & user_name & "','" & password & "','" & userProfile & "',1)"

happy coding
Mar 20 '07 #2
abedt
2 New Member
Thanks for the help

I a new error, it's:
Expected query name after EXECUTE
Mar 20 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
2219
by: Gérard Leclercq | last post by:
ACCESS First fields are TEXT, last 2 are Numbers The name of the fields are correct. Dim MyConn Set MyConn=Server.CreateObject("ADODB.Connection") MyConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath ("/xdata/sc.mdb")
4
18062
by: dcarson | last post by:
I've read about this error in several other discussions, but still can't seem to pinpoint the problem with my code. Everything seemed to be working fine for some time, but it now tends to bomb out on me for some reason. The Summary field is pulled from a Rich Text Editor that allows HTML formatting and appears to be the culprit, but I just can't seem to figure out why. Any guidance is greatly appreciated. I'm connecting to an Access...
3
4782
by: William | last post by:
i am using a dataset and a DataAdapter to update a table with the following schema: ResourceID ProjectID LastName FirstName Year Nov Dec Jan
7
6685
by: kosta | last post by:
hello! one of my forms communicates with a database, and is supposed to add a row to a table using an Insert statement... however, I get a 'oledb - syntax error' exception... I have double checked, and the insert works fine (tried to use it from access)... im using visual C# express 2k5... what could be wrong? thanks!
2
1607
by: eric dugal | last post by:
Hi all!! I need your help.... i'm working since 2 hours on a simple insert statement, but couldn't handle it. Here is my code : public int ExecQuery(string SqlString) {
3
2827
by: Neil Zanella | last post by:
Hello, I am trying to execute ADO.NET INSERT statement where one of the fields is coming from a password HTML control. When I access the text with password.Value and print with Response.Write so as to check that it is working correctly it displays just fine. However, whenever I include the password field in one of the SQL INSERT statement's fields I get the following error:
3
2505
by: Nathan Sokalski | last post by:
When trying to submit data to an Access database using ASP.NET I recieve the following error: System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr) +41 System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) +174 System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) +92
5
2150
by: amitbadgi | last post by:
Hi guys, I am getting the following error in teh insert statement , I am converting this asp application to asp.net, here is teh error, Exception Details: System.Runtime.InteropServices.COMException: Syntax error in INSERT INTO statement. Source Error: Line 118: MM_editCmd.ActiveConnection = MM_editConnection
2
2822
by: RSH | last post by:
I have a rather simple script that transfers data from a SQL server database to an Access database. The procedure is intended to be dynamic so I am basically adding a datarow and then passing the data with a simple loop. I am using OleDbCommandbuilder to build the INSERT command but for some reason when it gets to a particular table in the database it errors out giving me "Syntax Error in INSERT INTO Statement". The cmmandbuilder built...
6
6009
by: ewpatton | last post by:
Good day, I've been trying to work with SQL and an Access database in order to handle custom user profiles. I haven't had any trouble reading from my database, but inserting new entries into it has been troublesome to say the least. My ASP.NET script is supposed to execute an INSERT INTO statement in order to add a user to the database. Here is a sample:
0
9865
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
10932
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...
0
10609
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10303
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9446
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...
0
5692
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
5881
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4498
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
2
4082
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.