INSERT INTO USER
(fname,
mname,
lname,
uname,
password,
status,
address,
gender,
bdaym,
bdayd,
bdayy,
age,
contact,
isactive,
iscancelled)
VALUES ('" & SafeSTR(TextBox1.Text) & "',
'" & SafeSTR(TextBox2.Text) & "',
'" & SafeSTR(TextBox3.Text) & "',
'" & SafeSTR(TextBox7.Text) & "',
'" & SafeSTR(MD5(TextBox9.Text)) & "',
'" & SafeSTR(Combobox2.text) & "',
'" & SafeSTR(TextBox4.Text) & "',
'" & SafeSTR(ComboBox1.Text) & "',
'" & SafeSTR(ComboBox3.Text) & "',
'" & SafeSTR(ComboBox4.Text) & "',
'" & SafeSTR(ComboBox5.Text) & "',
'" & SafeSTR(TextBox5.Text) & "',
'" & SafeSTR(TextBox6.Text) & "',
1,
0)
what is the problem in my query?
From you comment
in vb.net i dont have any errors but i check my query in the query
database i got an error in sql syntax error
You are getting this error when you are executing it in database query editor because you are putting dynamic value instead of static value. If you want to execute this in database query editor put static value. For example :
INSERT INTO USER
(fname,
mname,
lname,
.
.
.
isactive,
iscancelled)
VALUES ('ABC',
'XYZ',
'PQR',
.
.
.
1,
0)
Related
still new to this, I wanted to add a combobox to my sql statement and keep getting an error. Can someone explain how to fix and how to add more combobox statements. I have about 20 columns, just testing one at a time.
Private Sub btn_Add_Click()
CurrentDb.Execute _
"INSERT INTO IPA_Raw_Data([Date], Auditor, Line_Clearance) " & _
"VALUES (#" & Format(Me!txt_Date.Value, "yyyy\/mm\/dd") & "#,'" & _
Me!txt_Name.Value & "','" & Me!cb_LC.Value & "')"
btn_Clear_Click
I was able to get it to work! I'm sorry for the delayed response and thank you guys for input. It was just syntax of the way I entered it.
Private Sub btn_Add_Click()
CurrentDb.Execute _
"INSERT INTO IPA_Raw_Data(Date_IPA, Auditor, Area, Operator, Safely, LineClearance, PPE, VerifyDoc, GVI, CompBefore, NonConf, ProcSteps, Trained, Points, Comments) " & _
"VALUES ('" & Me.txt_Date.Value & "', '" & Me!txt_Name.Value & "', '" & Me!txt_Area.Value & "', '" & Me!txt_Operator.Value & "', '" & Me!cb_Safe.Value & "', '" & Me!cb_LC.Value & "', '" & Me!cb_PPE.Value & "', '" & Me!cb_VDP.Value & "', '" & Me!cb_GVI.Value & "', '" & Me!cb_CBF.Value & "', '" & Me!cb_NC.Value & "', '" & Me!cb_ProStep.Value & "', '" & Me!cb_TrainProc.Value & "', '" & Me!txt_Points.Value & "', '" & Me!txt_Comment.Value & "')"
btn_Clear_Click
End Sub
I am a Create Customer form with a button and the following textboxes: txtCustomerID, txtFirstName, txtLastName, txtPhone, txtEmail. When I click the button, the information typed in the textboxes are inserted into [Customer] table and creates a folder based on the value of txtCustomerID, txtFirstName, and txtLastName. For example, if..
txtCustomerID: 100
txtFirstName: Ron
txtLastName: Smith
I want the folder name to display "100 - Ron Smith", but I can't find a solution to do that.
Below is the code that I used and it works perfectly, I just can't get it to the way I want to display the folder name.
Private Sub btnCreate_Click()
DoCmd.RunSQL "INSERT INTO [Customer] (CustomerID, FirstName, LastName, Phone, Email) VALUES ('" & Me.txtCustomerID & "', '" & Me.txtFirstName & "', '" & Me.txtLastName & "', '" & Me.txtPhone & "', '" & Me.txtEmail & "')"
MkDir ("C:\Users\Desktop\" & txtCustomerID.Value & txtFirstName.Value & txtLastName.Value)
End Sub
Any help or suggestion would be great. Thank you
MkDir ("C:\Users\Desktop\" & txtCustomerID.Value & " - " & txtFirstName.Value & " " & txtLastName.Value)
will add the dash and spaces that you want.
Should be as simple as putting in spaces.....
Private Sub btnCreate_Click()
DoCmd.RunSQL "INSERT INTO [Customer] (CustomerID, FirstName, LastName, Phone, Email) VALUES ('" & Me.txtCustomerID & "', '" & Me.txtFirstName & "', '" & Me.txtLastName & "', '" & Me.txtPhone & "', '" & Me.txtEmail & "')"
MkDir ("C:\Users\Desktop\" & txtCustomerID.Value & " - " & txtFirstName.Value & " " & txtLastName.Value)
End Sub
I don't seem to find out what is wrong with my query. The values at the end are the name of the variables
Command.CommandText = (" INSERT INTO [TransfersAndAdditionalCourses]
(TransferCourse1,TransferCourse2, TransferCourse3,
TransferCourse4, TransferCourse5, AdditionalCourse1,
AdditionalCourse2, AdditionalCourse3, AdditionalCourse4, AdditionalCourse5)
VALUES ('" & firstTransferCourse & ",' " & secondTransferCourse
& "," & thirdTransferCourse & " ', '" & fourthTransferCourse & " ','"
& fifthTransferCourse & " ', '" & firstAdditionalCourse & ", "
& secondAdditionalCourse & "',' " & thirdAdditionalCourse & "',' "
& fourthAdditionalCourse & "','" & fifthAdditionalCourse & "' ")
Thanks
You seem to me missing some single quotation marks.
Please try this:
Command.CommandText = ("INSERT INTO [TransfersAndAdditionalCourses]
(TransferCourse1,TransferCourse2, TransferCourse3, TransferCourse4,
TransferCourse5, AdditionalCourse1, AdditionalCourse2, AdditionalCourse3,
AdditionalCourse4, AdditionalCourse5)
VALUES ('" & firstTransferCourse & "',' " & secondTransferCourse & "', '"
& thirdTransferCourse & " ', '" & fourthTransferCourse & " ','"
& fifthTransferCourse & " ', '" & firstAdditionalCourse & "', '"
& secondAdditionalCourse & "',' " & thirdAdditionalCourse & "',' "
& fourthAdditionalCourse & "','" & fifthAdditionalCourse & "' ")
Format the insert query and you will see the mistakes, you are missing the quotes in many places, also the leading ( and tailing ) is not needed. It should look like something as
Command.CommandText =
"
INSERT INTO [TransfersAndAdditionalCourses]
(
TransferCourse1,
TransferCourse2,
TransferCourse3,
TransferCourse4,
TransferCourse5,
AdditionalCourse1,
AdditionalCourse2,
AdditionalCourse3,
AdditionalCourse4,
AdditionalCourse5
)
VALUES
(
'" & firstTransferCourse & "',
'" & secondTransferCourse & "',
'" & thirdTransferCourse & "',
'" & fourthTransferCourse & "',
'" & fifthTransferCourse & "',
'" & firstAdditionalCourse & "',
'" & secondAdditionalCourse & "',
'" & thirdAdditionalCourse & "',
'" & fourthAdditionalCourse & "',
'" & fifthAdditionalCourse & "'
)"
im taking too much time for this error and can't find the error here
Adapter = New MySqlDataAdapter("Insert into tbluser(UserID,Name,UserType,Password) values('" & txtUserId.Text & "' ,'" & txtName.Text & "','" & cmbUserType.Text & "','" & "',AES_ENCRYPT('" & txtpass.Text & "','x'))", connection)
Adapter = New MySqlDataAdapter("Insert into tbluser (UserID
,Name
,UserType
,Password)
values( '" & txtUserId.Text & "'
, '" & txtName.Text & "'
, '" & cmbUserType.Text & "'
, '" & "'
, AES_ENCRYPT('" & txtpass.Text & "','x'))", connection)
You have more values than you have defined columns to insert. It looks like the problem is an empty field between the UserType and the Password. Revise it like so should resolve the column count error:
Adapter = New MySqlDataAdapter("Insert into tbluser ( UserID
, Name
, UserType
, Password)
values( '" & txtUserId.Text & "'
, '" & txtName.Text & "'
, '" & cmbUserType.Text & "'
, AES_ENCRYPT('" & txtpass.Text & "','x'))"
, connection)
I am using this code to insert 4 textboxes of data into a table.
CurrentDb.Execute = "INSERT INTO tbl_machineheader(Line No, Description, Service Interval, Type) values ( '" & Me.Combo3 & "', '" & Me.Text1 & "', '" & Me.Text6 & "', '" & Me.Text12 & "')"
However it doesn't seem to work and I can't figure out why.
That "=" character is wrong:
CurrentDb.Execute **=** "INSERT INTO tbl_machineheader(Line No, Description, Service Interval, Type) values ( '" & Me.Combo3 & "', '" & Me.Text1 & "', '" & Me.Text6 & "', '" & Me.Text12 & "')"
Also you should use square brackets for your column names. The correct syntax is as follows:
CurrentDb.Execute "INSERT INTO tbl_machineheader([Line No], [Description], [Service Interval], [Type]) values ( '" & Me.Combo3 & "', '" & Me.Text1 & "', '" & Me.Text6 & "', '" & Me.Text12 & "')"