First off I started my code with:
Comm2 = "INSERT INTO [Results]" _
& "([ResultsID], [TestID], [Thickness], [SNR], [STD], [M1], [M2], [kVp], [mAs], [TargetFilter])" _
& " values('" & CInt(NewRID) & " ', '" & CInt(NewRID) & " ', '" & Thickness & "', '" & SNR & "', '" & STD & "','" & M1 & "', '" & M2 & "', '" & kVp & "', '" & mAs & "', '" & TargetFilter & "')"
Comm3 = "INSERT INTO [Test]" _
& "([TestID], [Date], [MachineID], [RadiographerID])" _
& " values('" & CInt(NewRID) & " ', '" & todaysdate & " ', '" & 1 & " ', '" & UserID & " ',)"
However this didn't work as the tables are related in the database so had to change them at the same time, so i am currently trying this:
Comm2 = "INSERT INTO [Results] ([ResultsID],[TestID],[Tickness],[SNR],[STD],[M1],[M2],[kVp],[mAs],[TargetFilter]) VALUES('" & CInt(NewRID) & " ', '" & CInt(NewRID) & " ', '" & Thickness & "', '" & SNR & "', '" & STD & "','" & M1 & "', '" & M2 & "', '" & kVp & "', '" & mAs & "', '" & TargetFilter & "');" _
& "INSERT INTO [Test] ([TestID], [Date[, [MachineID], [RadiographerID]) VALUES('" & CInt(NewRID) & " ', '" & CDate(todaysdate) & " ', '" & CInt(MachineID) & "', '" & CStr(UserID) & "')"
OleDbInsertCommand.Connection = conn
OleDbInsertCommand.CommandText = Comm2
adapter2.InsertCommand = OleDbInsertCommand
adapter2.InsertCommand.ExecuteNonQuery()
And I am getting this error:
https://gyazo.com/36aa32cbfb0f54bbe571f6a9384114e1
Comm2 = "INSERT INTO [Results] ([ResultsID], [TestID], [Thickness], [SNR], [STD], [M1], [M2], [kVp], [mAs],[TargetFilter]) VALUES('" & CInt(NewRID) & " ', '" & CInt(NewRID) & " ', '" & Thickness & "', '" & SNR & "', '" & STD & "','" & M1 & "', '" & M2 & "', '" & kVp & "', '" & mAs & "', '" & TargetFilter & "')"
comm3 = " INSERT INTO [Test] ([TestID], [Date], [MachineID], [RadiographerID]) VALUES('" & CInt(NewRID) & " ', '" & CDate(todaysdate) & " ', '" & CInt(MachineID) & "', '" & CInt(UserID) & "')"
OleDbInsertCommand.Connection = conn
OleDbInsertCommand.CommandText = comm3
adapter2.InsertCommand = OleDbInsertCommand
adapter2.InsertCommand.ExecuteNonQuery()
OleDbInsertCommand.CommandText = Comm2
adapter2.InsertCommand = OleDbInsertCommand
adapter2.InsertCommand.ExecuteNonQuery()
Comm2 = "INSERT INTO [Results] ([ResultsID], [TestID], [Thickness], [SNR], [STD], [M1], [M2], [kVp], [mAs],[TargetFilter]) VALUES('" & CInt(NewRID) & " ', '" & CInt(NewRID) & " ', '" & Thickness & "', '" & SNR & "', '" & STD & "','" & M1 & "', '" & M2 & "', '" & kVp & "', '" & mAs & "', '" & TargetFilter & "')"
comm3 = " INSERT INTO [Test] ([TestID], [Date], [MachineID], [RadiographerID]) VALUES('" & CInt(NewRID) & " ', '" & CDate(todaysdate) & " ', '" & CInt(MachineID) & "', '" & CInt(UserID) & "')"
OleDbInsertCommand.Connection = conn
OleDbInsertCommand.CommandText = comm3
adapter2.InsertCommand = OleDbInsertCommand
adapter2.InsertCommand.ExecuteNonQuery()
OleDbInsertCommand.CommandText = Comm2
adapter2.InsertCommand = OleDbInsertCommand
adapter2.InsertCommand.ExecuteNonQuery()
Related
The Error shows its there is an Invalid of the . (Dot) Or ! operator
If IsNull(Me.m_1) Or IsNull(Me.u_1) Or Me.m_1 = "" Or Me.u_1 = "" Then
MsgBox "Please add all needed info"
Else
sqls = "INSERT INTO User_access (Application_ID, Modul_ID, username_ID, Clock_ID, Assinged_date, Assinged_by, Request_number) values('" & Me.A_1 & "', '" & Me.m_1 & "', '" & Me.u_1 & "', '" & Me.Clock_ID & "', '" & Date & "', '" & Me.Assinged_by & "', '" & Me.Request_number & "');"
DoCmd.RunSQL sqls
End If
I cannot see any error within the code So please Help me
Use Date():
sqls = "INSERT INTO User_access (Application_ID, Modul_ID, username_ID, Clock_ID, Assinged_date, Assinged_by, Request_number) values('" & Me.A_1 & "', '" & Me.m_1 & "', '" & Me.u_1 & "', '" & Me.Clock_ID & "', Date(), '" & Me.Assinged_by & "', '" & Me.Request_number & "');"
And no quoting of numeric values.
I'm doing a project and I just used some code from YouTube where it seemed to work, but it isn't working for me. I am getting this message. :/
Run-time Error: '3134':
Syntax Error in INSERT INTO statement.
Here's the code:
Private Sub Dodaj_Click()
CurrentDb.Execute "INSERT INTO Rezervacije( JMBG, Grad, Broj dana, Broj osoba) " & _
" VALUES('" & Me.JMBG & "', '" & Me.Destinacija & "', '" & Me.Dani & "', '" & Me.Osobe & "')"
CurrentDb.Execute "INSERT INTO Putnici(Broj licne karte, Ime, Prezime, JMBG, Mobilni, Email, Pol) " & _
" VALUES('" & Me.Licna & "', '" & Me.Ime & "', '" & Me.Prezime & "', '" & Me.JMBG & "', '" & Me.Mobilni & "', '" & Me.Email & "', '" & Me.Pol & "')"
End Sub
I have a problem of syntax ( rror 3134) with my SQL query....
Here is the query :
StrSQL1 = "INSERT INTO Repos (Num_utilisateur, Nb_conges_semaine1, Nb_conges_semaine2, Nb_conges_semaine3, Nb_conges_semaine4, Total_conges_mois1, Nb_conges_semaine5, Nb_conges_semaine6, Nb_conges_semaine7, Nb_conges_semaine8, Total_conges_mois2, Nb_conges_semaine9, Nb_conges_semaine10, Nb_conges_semaine11, Nb_conges_semaine12, Total_conges_mois3, Nb_JoursFeries_semaine1, Nb_JoursFeries_semaine2, Nb_JoursFeries_semaine3, Nb_JoursFeries_semaine4, Total_Nb_JoursFeries_mois1, Nb_JoursFeries_semaine5, Nb_JoursFeries_semaine6, Nb_JoursFeries_semaine7, Nb_JoursFeries_semaine8, Total_Nb_JoursFeries_mois2, Nb_JoursFeries_semaine9, Nb_JoursFeries_semaine10, Nb_JoursFeries_semaine11, Nb_JoursFeries_semaine12, Nb_AutresAbsences_semaine1, Nb_AutresAbsences_semaine2, Nb_AutresAbsences_semaine3, Nb_AutresAbsences_semaine4, Total_Nb_AutresAbsences_mois1, Nb_AutresAbsences_semaine5, Nb_AutresAbsences_semaine6, Nb_AutresAbsences_semaine7, Nb_AutresAbsences_semaine8," & _ "# Total_Nb_AutresAbsences_mois2, Nb_AutresAbsences_semaine9, Nb_AutresAbsences_semaine10, Nb_AutresAbsences_semaine11, Nb_AutresAbsences_semaine12, Total_Nb_AutresAbsences_mois3, Total_general) VALUES ('" & NumAgent & "', '" & Conges_1 & "', '" & Conges_2 & "', '" & Conges_3 & "', '" & Conges_4 & "', '" & CongesTotalMois1 & "', '" & Conges_5 & "', '" & Conges_6 & "', '" & Conges_7 & "', '" & Conges_8 & "', '" & CongesTotalMois2 & "', '" & Conges_9 & "', '" & Conges_10 & "', '" & Conges_11 & "', '" & Conges_12 & "', '" & CongesTotalMois3 & "', '" & JourFeriee_1 & "', '" & JourFeriee_2 & "', '" & JourFeriee_3 & "', '" & JourFeriee_4 & "', '" & JourFerieeTotalMois1 & "', '" & JourFeriee_5 & "', '" & JourFeriee_6 & "', '" & JourFeriee_7 & "', '" & JourFeriee_8 & "', '" & JourFerieeTotalMois2 & "', '" & JourFeriee_9 & "', '" & JourFeriee_10 & "', '" & JourFeriee_11 & "', '" & JourFeriee_12 & "', '" & JourFerieeTotalMois3 & "'," & _ "# '" & JourAutre1 & "', '" & JourAutre2 & "', '" & JourAutre3 & "', '" & JourAutre4 & "', '" & JourAutreTotalMois1 & "', '" & JourAutre5 & "', '" & JourAutre6 & "', '" & JourAutre7 & "', '" & JourAutre8 & "', '" & JourAutreTotalMois2 & "', '" & JourAutre9 & "', '" & JourAutre10 & "', '" & JourAutre11 & "', '" & JourAutre12 & "', '" & JourAutreTotalMois3 & "', '" & TotalGeneral & "');"
Sorry It's a long query...
Thank you in advance for your help !
if i do not see wrong i count 46 fields but 47 values. The number of fields and values must be the same.
Your have in your INSERT clause:
# Total_Nb_AutresAbsences_mois2
In your VALUES clause:
# JourAutre1
They're invalid field names.
Try removing the # symbol.
Edit:
Both #Karthick and #Michelle are correct as you're missing that field in your results.
Also hope I'm correct about the # symbol being invalid.
I have this huge problem with my vb.net code. Everything seem fine and i cant quite figure out where the problem is. I want to submit a record to an Access database but i get this datatype mismatch error everytime. My access database is all text for the fields. except for the dates which have datatype DATE.
Try
'LGCodeHygNumb()
Dim statement As String
Dim cmd As OleDbCommand
Dim connect As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Persist Security Info=false; Data Source=..\ClosedIn11.mdb")
'If connect.State = ConnectionState.Closed Then
connect.Open()
'End If
statement = "INSERT INTO EnrolleeDets (ID, Surname, FirstName, Othername, ReceiptNumber, Birthdate, Gender, MaritalStatus, HomeAddress, Mobile, Telephone, State, StateCode, Local_Govt, GroupType, GroupName, Location, ElectiveType, Provider, PassportDirectory, Original_RegDate, New_RenewalDate, ExpiryDate, Status, OverallStatus) values ('" & lblnumb.Text & "', '" & txtSurnanme.Text & "', '" & txtFirstname.Text & "', '" & txtNickname.Text & "', '" & txtReceiptNo.Text & "', '" & DatePicker1.Text & "', '" & cmbGender.Text & "', '" & cmbMaritalStatus.Text & "', '" & txtHomeAddr.Text & "', '" & txtMobile.Text & "', '" & TextBox8.Text & "', '" & cmbState.Text & "', '" & cmbStateCode.Text & "', '" & cmbLGACode.Text & "', '" & cmbGroupType.Text & "', '" & cmbGroupName.Text & "', '" & cmbLocation.Text & "', '" & cmbElectiveType.Text & "', '" & cmbProvider.Text & "', '" & txtPassportDir.Text & "','" & txtPassportDir.Text & "', '" & txtPassportDir.Text & "', '" & txtPassportDir.Text & "', '" & txtPassportDir.Text & "', '" & txtPassportDir.Text & "')"
'MsgBox(statement)
cmd = New OleDbCommand(statement, connect)
cmd.ExecuteNonQuery()
'MsgBox(lblnumb.Text & " added under " & txtSurnanme.Text & " !", vbInformation)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
'connect.Close()
In your statement:
statement = "INSERT INTO EnrolleeDets (ID, Surname, FirstName, Othername, ReceiptNumber, Birthdate, Gender, MaritalStatus, HomeAddress, Mobile, Telephone, State, StateCode, Local_Govt, GroupType, GroupName, Location, ElectiveType, Provider, PassportDirectory, Original_RegDate, New_RenewalDate, ExpiryDate, Status, OverallStatus) values ('" & lblnumb.Text & "', '" & txtSurnanme.Text & "', '" & txtFirstname.Text & "', '" & txtNickname.Text & "', '" & txtReceiptNo.Text & "', '" & DatePicker1.Text & "', '" & cmbGender.Text & "', '" & cmbMaritalStatus.Text & "', '" & txtHomeAddr.Text & "', '" & txtMobile.Text & "', '" & TextBox8.Text & "', '" & cmbState.Text & "', '" & cmbStateCode.Text & "', '" & cmbLGACode.Text & "', '" & cmbGroupType.Text & "', '" & cmbGroupName.Text & "', '" & cmbLocation.Text & "', '" & cmbElectiveType.Text & "', '" & cmbProvider.Text & "', '" & txtPassportDir.Text & "','" & txtPassportDir.Text & "', '" & txtPassportDir.Text & "', '" & txtPassportDir.Text & "', '" & txtPassportDir.Text & "', '" & txtPassportDir.Text & "')"
Your columns Original_RegDate, New_RenewalDate, ExpiryDate match up with '" & txtPassportDir.Text & "', '" & txtPassportDir.Text & "', '" & txtPassportDir.Text & "'
I would guess that txtPassportDir.Text does not contain a date.
You should create the command using OleDbParameters.
statement = "INSERT INTO EnrolleeDets (Surname, Birthdate, Status) values (#ID, #Birthdate, #Status);"
Make sure that the added values have correct data type:
cmd.Parameters.AddWithValue("#Surname", Me.TextBox1.Text) ' VarChar
cmd.Parameters.AddWithValue("#Birthdate", Date.Parse(Me.TextBox2.Text)) 'DateTime
cmd.Parameters.AddWithValue("#Status", Integer.Parse(Me.TextBox3.Text)) 'Int
is this command correct for inserting a single value,
"INSERT INTO test (testname) values ('" & txtSelect.Text & "')"
actually i'm trying to insert via this command, but its not working..
"INSERT INTO AdmitPt(Bedcategory, BedNo, BedCharges, PtName, PtAge, Address, PhoneNo,
Date, BloodGroup, Doctor, Remarks) VALUES('" & CmbBedType.SelectedItem & "', '" &
CmbBedNo.SelectedItem & "', " & txtCharges.Text & "', '" & txtPatName.Text & "', '" &
txtPatAge.Text & "', '" & txtPatAdd.Text & "', '" & txtPhone.Text & "', '" &
dtpDate.Value.ToShortDateString & "', '" & cmbBloodGrp.SelectedItem & "', '" &
cmbDoctor.SelectedItem & "', " & txtRemarks.Text & ")"
kindly correct me i'm doing some mistake.
If you posted your entire code - you forgot to actually execute the command. Add
comStudent.ExecuteNonQuery()
before closing the connection.
You should be using Text property of SelectedItem
"INSERT INTO AdmitPt(Bedcategory, BedNo, BedCharges, PtName, PtAge, Address, PhoneNo,
Date, BloodGroup, Doctor, Remarks) VALUES('" & CmbBedType.SelectedItem.Text & "', '" &
CmbBedNo.SelectedItem.Text & "', " & txtCharges.Text & "', '" & txtPatName.Text & "', '" &
txtPatAge.Text & "', '" & txtPatAdd.Text & "', '" & txtPhone.Text & "', '" &
dtpDate.Value.ToShortDateString() & "', '" & cmbBloodGrp.SelectedItem.Text & "', '" &
cmbDoctor.SelectedItem.Text & "', " & txtRemarks.Text & ")"
also ToShortDateString is a method and should be writen as ToShortDateString()
no exception is generated, but values are not going to DB.. not stored..
code
Dim RegNo, BedNo, BedType, Charges, PatName, PatAge, PatAddr, Phone, CheckupDate, BloodGroup, Doctor, Remarks As String
RegNo = txtRegNo.Text
BedNo = CmbBedNo.SelectedItem.ToString()
BedType = CmbBedType.SelectedItem.ToString()
Charges = txtCharges.Text
PatName = txtPatName.Text
PatAge = txtPatAge.Text
PatAddr = txtPatAdd.Text
Phone = txtPhone.Text
CheckupDate = dtpDate.Value.ToShortDateString()
BloodGroup = cmbBloodGrp.SelectedItem.ToString()
Doctor = cmbDoctor.SelectedItem.ToString()
Remarks = txtRemarks.Text
conStudent.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\DBProject\hspms.mdb"
conStudent.Open()
comStudent.CommandText = "INSERT INTO AdmitPt(ID, Bedcategory, BedNo, BedCharges, PtName, PtAge, Address, PhoneNo, Date, BloodGroup, Doctor, Remarks) VALUES('" & RegNo & "', '" & BedType & "', '" & BedNo & "', " & Charges & "', '" & PatName & "', '" & PatAge & "', '" & PatAddr & "', '" & Phone & "', '" & CheckupDate & "', '" & BloodGroup & "', '" & Doctor & "', " & Remarks & ")"
comStudent.Connection = conStudent
comStudent.CommandType = CommandType.Text
conStudent.Close()
code