By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,948 Members | 860 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,948 IT Pros & Developers. It's quick & easy.

Problems with INSERT statement sent to Access

P: 1
hi pls someone help me whit this i need to fill a table from visual basic but i try at least every code that have in the net pls someone pls help this is the last code that i imput

Expand|Select|Wrap|Line Numbers
  1. Dim sql As String
  2. Dim mycon As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
  3.     "Data Source = gigtoyo.mdb"
  4. Dim dt As New DataTable
  5. sql = "INSERT INTO invoice(invoice, fechatrans, descripcion, nombre, " _
  6.     & modelo, pronto, casafina, fina, total)VALUES(" _
  7.     & TextBox9.Text & ", #" & DateTimePicker1.Text & "#, '" _
  8.     & TextBox3.Text & "', '" & TextBox1.Text & "', '" & TextBox2.Text _
  9.     & "', '" & TextBox7.Text & "', " & TextBox6.Text & ", " _
  10.     & TextBox8.Text & ", " & TextBox4.Text & ")"
  11. Dim sqlexe As New OleDb.OleDbDataAdapter(sql, mycon)
  12. sqlexe.Fill(dt)
  13. sqlexe.Dispose()
May 6 '07 #1
Share this Question
Share on Google+
3 Replies


Dököll
Expert 100+
P: 2,364
hi pls someone help me whit this i need to fill a table from visual basic but i try at least every code that have in the net pls someone pls help this is the last code that i imput
Expand|Select|Wrap|Line Numbers
  1.  
  2.         Dim sql As String
  3.         Dim mycon As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source = gigtoyo.mdb"
  4.         Dim dt As New DataTable
  5.         sql = "INSERT INTO invoice(invoice, fechatrans, descripcion, nombre, modelo, pronto, casafina, fina, total)VALUES(" & TextBox9.Text & ", #" & DateTimePicker1.Text & "#, '" & TextBox3.Text & "', '" & TextBox1.Text & "', '" & TextBox2.Text & "', '" & TextBox7.Text & "', " & TextBox6.Text & ", " & TextBox8.Text & ", " & TextBox4.Text & ")"
  6.         Dim sqlexe As New OleDb.OleDbDataAdapter(sql, mycon)
  7.         sqlexe.Fill(dt)
  8.         sqlexe.Dispose()
Expand|Select|Wrap|Line Numbers
  1.  
  2.  
Hello, omi1800!

You are missing single quotes in your VALUES command:

('" & TextBox9.Text & "', and others within the same command

You now have (" & TextBox9.Text & ",

Also, I do not think #" & DateTimePicker1.Text & "#, will work, try getting rid of the # sign there, add single quotes run it again.

Good luck with the project!

Dököll
May 7 '07 #2

Expert 5K+
P: 8,434
...
Also, I do not think #" & DateTimePicker1.Text & "#, will work, try getting rid of the # sign there, add single quotes run it again.
If the field type is Date/Time, then I'm fairly certain you do need the # delimiters. However, you should force the date into U.S. format (mm/dd/yyyy). Alternatively, I think you can probably get away with a format which can't be easily confused, such as one with the month in text (Eg. #7 May 2007#).

By the way omi1800, you didn't say what the problem is, or what version of VB you're using.
May 7 '07 #3

Dököll
Expert 100+
P: 2,364
Ahhh! I was reminded of a query in VB 6, please carry on...Thanks.
May 8 '07 #4

Post your reply

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