number of query values and destination fields are not the same - ms-access

This is what I have for the Add Event.
CurrentDb.Execute "INSERT INTO tblMatchBook ([Patron], [Staff], [TimeReceived], [SurveyLink], [DateFinished], [BookTitles]) " & _
" Values('" & Me.ddBarcode & "," & Me.ddStaff & "," & Me.txtRDate & "," & Me.txtLink & "," & "" & "," & "" & "')"
I cannot figure out what is wrong.

insert into Main values (28494,1,False,'Buto-asma Sirop' , 'Buto-asma Sirop', 3.99 , 'Syrup', 'ispani', ' ', ' ',0, '1',4988 )

Related

Ms Access SQL VBA query error no 3075

In my Access application, I am trying to concat existing field value with new value and I have code as below written in VBA, I am getting error 3075 "syntax error missing operator"
sUser = UserNameWindows
' MsgBox sUser
currenttime = Format(Now(), "dd/mm/yyyy hh:mm:ss")
SqlQuery = "UPDATE tbl_AllRequests " & _
" SET [Status]= 'Archived' " & _
", [History] = [History] & CHR(13) & CHR(10) & 'Archived on' " & currenttime & " ' by ' & '" + sUser + "' " & _
" WHERE [ID] in (" & selectedIDs & ")"
'" SET [History] = concat([History], 'Archived on " & currenttime & " by '" & sUser & "'&')'&" & _
'data=concat(data, 'a')
'SqlQuery = "UPDATE tbl_AllRequests SET Status = 'Archived' WHERE ID in (17, 11)"
Debug.Print "this is new one " & SqlQuery
DoCmd.RunSQL SqlQuery, True
I am getting error on below line of code.
", [History] = [History] & CHR(13) & CHR(10) & 'Archived on' " & currenttime & " ' by ' & '" + sUser + "' " & _
If I remove the code after 'Archived on' it works.
Thanks
First correct this:
currenttime = Format(Now(), "dd/mm/yyyy hh:nn:ss")
Then, use only single quotes around your fixed text:
", [History] = ([History] + CHR(13) + CHR(10)) & 'Archived on '" & currenttime & "' by '" & sUser & "" & _
Also, it makes no sense first to format Now to a string expression, then convert (with errors) to a date value by wrapping it in octothorpes (#..#), which - when concatenated with the strings - will be casted once more to a string.

Too few parameters, expected 4;

Dim query As String
query = "insert into tbl_passenger(passenger_name,age,gender_id,address,phone_no,plane_no,seat_no,destination_id,time_id,price_id)values('" & _
Me.txtpassengername.Value & "'," & Me.txtage.Value & "," & Me.cmbgender.Column(1) & ",'" & Me.txtaddress.Value & "', " & Me.txtphone.Value & "," & _
Me.cmbplane.Column(1) & "," & Me.cmbseat.Column(1) & "," & Me.cmbdestination.Column(1) & "," & Me.cmbtime.Column(1) & "," & _
Me.cmbprice.Column(1) & ")"
CurrentDb.Execute (query)
MsgBox ("Data Inserted")
What is the problem here? The error I get is
Too few parameters, expected 4;
Insert a debug line:
Debug.Print query
CurrentDb.Execute (query)
MsgBox ("Data Inserted")
Study what you see, and you will know. Or post the output here.

updating day by day data in database using pentaho spoon

I have a SQL query as mentioned below and this will update DB every day comparing the date (latest appended date data will be updated in DB) and I want to do this in transformations using Pentaho Data Integration (Kettle).
Do While i < dgTest.RowCount
dd = Mid(dgTest.Item(2, i).Value, 5, 2) & "/" & Mid(dgTest.Item(2, i).Value, 7, 2) & "/" & Mid(dgTest.Item(2, i).Value, 1, 4)
Sql = "INSERT INTO cash ([comp], strno, bday, openread, curread,refqty,refamt, promoq," & _
" promoa, netsprod, netsnprod, eatintc, eatins, eatouttc, eatouts, " & _
" dttc, coffeetc, dts, coffeesales, csh, cover,recamt,crsalesamt ) Values " & _
" ('" & dgTest.Item(0, i).Value.ToString & "','" & dgTest.Item(1, i).Value.ToString & _
"',#" & CDate(dd) & "#,'" & dgTest.Item(3, i).Value.ToString & "'," & dgTest.Item(4, i).Value & "," & _
dgTest.Item(5, i).Value & "," & dgTest.Item(6, i).Value & _
"," & dgTest.Item(7, i).Value & _
"," & dgTest.Item(8, i).Value & "," & dgTest.Item(9, i).Value & _
"," & dgTest.Item(10, i).Value & "," & dgTest.Item(11, i).Value & _
"," & dgTest.Item(12, i).Value & "," & dgTest.Item(13, i).Value & "," & dgTest.Item(14, i).Value & _
"," & dgTest.Item(15, i).Value & "," & dgTest.Item(16, i).Value & "," & dgTest.Item(17, i).Value & "," & dgTest.Item(18, i).Value & "," & dgTest.Item(19, i).Value & "," & dgTest.Item(20, i).Value & "," & dgTest.Item(21, i).Value & "," & dgTest.Item(22, i).Value & ")"
cmd = New OleDbCommand(Sql, con)
cmd.ExecuteNonQuery()
i = i + 1
Loop
I don't understand the approach you are trying to implement but what you can do is from input table step read the data, use modified java-script and specify that on this particular time update the database.. example
var d = new Date();
var hour1 = d.getHours();
if(hour1==14)
{
if(d.getDate()==day2 && month1==month2 && year1==year2 && hour>=13 && hour<17)
}

having error with mysql vb.net [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
this is my code and im having the problems for 2 hours now
Dim Query As String
con.Open()
Query = "INSERT INTO `" & finalTableName & "` VALUES" & _
"(" & _
" '" & varDateTime & "'," & _
" '" & varComputer & "'," & _
" '" & vard & "'," & _
" '" & varll & "' ," & _
" '" & varPp & "'," & _
" '" & varVv & "' ," & _
" '" & varIi & "' ," & _
" '" & varIc & "'," & _
" '" & varPc & "'," & _
" '" & varSs & "'," & _
" '" & varRd & "'," & _
" '" & varIpd & "'," & _
" '" & varMg & "'," & _
" '', " & _
" '" & varRuleId & "', " & _
" '" & varDateUploaded & "' " & _
")"
Dim cmd As MySqlCommand = New MySqlCommand(Query, con)
If (cmd.ExecuteNonQuery()) Then
End If
con.Close()
This is the problem that im having
You have an error in your SQL syntax; check the manual that corresponds to
your MySQL server version for the right syntax to use near 'dd', 'Deleted',
'344', '', '4', '2014-03-05 15:29:37' )' at line 1
Use command parameters
Dim Query As String
Query = "INSERT INTO `" & finalTableName & _
"` VALUES(#1, #2, #3, #4, #5, #6, #7, #8, #9, #10, #11, #12, #13, '', #14, #15)"
Dim cmd As MySqlCommand = New MySqlCommand(Query, con)
cmd.AddWithValue("#1", varDateTime);
cmd.AddWithValue("#2", varComputer);
cmd.AddWithValue("#3", vard);
cmd.AddWithValue("#4", varll);
cmd.AddWithValue("#5", varPp);
cmd.AddWithValue("#6", varVv);
cmd.AddWithValue("#7", varIi);
cmd.AddWithValue("#8", varIc);
cmd.AddWithValue("#9", varPc);
cmd.AddWithValue("#10", varSs);
cmd.AddWithValue("#11", varRd);
cmd.AddWithValue("#12", varIpd);
cmd.AddWithValue("#13", varMg);
cmd.AddWithValue("#14", varRuleId);
cmd.AddWithValue("#15", varDateUploaded);
con.Open()
If cmd.ExecuteNonQuery() = 1 Then
End If
con.Close()
The parameters will automatically be add the right way correponding the column type (text as text, numbers as numbers, dates as dates).
Also I recommend to add the column names part. This makes the command safer. If you later add or remove columns and the column order is changed, it will still work or at least throw an exception and not silently insert a value into a wrong column.
INSERT INTO table (col1, col2, col3) VALUES (val1, val2, val3)
Get rid of the ` and use ' instead.
As in:
`" & finalTableName & "`
should be
'" & finalTableName & "'

how to concatenate sql query in newline in vb6.0?

i want to concatenate sql query that is not in single line but new line .
Conn.Execute "insert into users("
"FirstName,"
"LastName,"
"Address1,"
"Address2,"
")values("
" UCase(txtfirstname.Text) &" ,
"& UCase(txtlastname.Text) &",
" & UCase(txtaddress1.Text) & ",
" & UCase(txtaddress2.Text) & "
")"
how to concatenate them into single one?
Thanks ,
Yugal
In the VB6 to do a line continuation you end a line with [space][underscore]. You also need to use the & to concatenate the text segments on each line together. So the line would look something like this:
Conn.Execute "insert into users(" _
& "FirstName," _
& "LastName," _
& "Address1," _
& "Address2" _
& ")values(" _
& UCase(txtfirstname.Text) & "," _
& UCase(txtlastname.Text) & "," _
& UCase(txtaddress1.Text) & "," _
& UCase(txtaddress2.Text) _
& ")"
Something like this perhaps:
Conn.Execute "insert into users(FirstName, LastName, Address1, Address2) values('" & UCase(txtfirstname.Text) & "', '" & UCase(txtlastname.Text) & "', '" & UCase(txtaddress1.Text) & "', '" & UCase(txtaddress2.Text) & "'")"