1 Replies - 371 Views - Last Post: 26 November 2012 - 07:51 AM Rate Topic: -----

#1 wilsons  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 26-November 12

vb.net 2008 express edition and access 2007

Posted 26 November 2012 - 04:29 AM

Hi there, I am new to vb.net programming. I am developing a point of sale application and am having trouble writing data to access 2007 database. Am getting an error "Syntax error in INSERT INTO statement,"

my code for the form load is:



[Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

dbProvider = "PROVIDER=Microsoft.ACE.OLEDB.12.0;"
dbSource = "Data Source= C:\users\newton\Documents\wilson.accdb"

con.ConnectionString = dbProvider & dbSource


con.Open()
sql = "SELECT tblLogin.Username, tblLogin.Password FROM tblLogin"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "Login")

con.Close()

MaxRows = ds.Tables("Login").Rows.Count
inc = -1


End Sub][/code]


and the code for the save button is


[Private Sub btnCommit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
If inc <> -1 Then
Dim cb As New OleDb.OleDbCommandBuilder(da)
Dim dsNewRow As DataRow

dsNewRow = ds.Tables("Login").NewRow()

dsNewRow.Item("Username") = txtUsername.Text
dsNewRow.Item("Password") = txtPassword.Text



ds.Tables("Login").Rows.Add(dsNewRow)
da.Update(ds, "Login")



End If
End Sub
][/code]

Is This A Good Question/Topic? 0
  • +

Replies To: vb.net 2008 express edition and access 2007

#2 tlhIn`toq  Icon User is online

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5674
  • View blog
  • Posts: 12,189
  • Joined: 02-June 10

Re: vb.net 2008 express edition and access 2007

Posted 26 November 2012 - 07:51 AM

Please fix your code tags

:code:

sql = "SELECT tblLogin.Username, tblLogin.Password FROM tblLogin"

This almost looks like you are trying to parameterize the query, but not doing it right. You can't just shove in a GUI control.property withing a pair of quotes and expect it to work. How would your code know you want the text from tblLogin.Username and not literally "tblLogin.Usernam"?

from my FAQ list:


Q:... how to do x,y,z with a database {probably for the first time}...
A: Read this tutorial
Entire section of tutorials
Parameterizing Your SQL Queries: The RIGHT Way To Query A Database.
Using SqlDependency to monitor SQL database changes
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1