Results 1 to 2 of 2

Thread: Another Access problem help before i kill someone

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Location
    Outer space
    Posts
    97

    Angry Another Access problem help before i kill someone

    below is a function i've been using to save a user to a db

    - i've used the command builder to generate my SQL but it keeps returning 'syntax error in insert command' and i can't see what im doing wrong n e help would be appreciated

    Public Function SaveUser() As String
    'Dim MyDs As New System.Data.DataSet()
    Dim MyDs As New StandardClasses.NWDataSet()
    Dim MyDa As New OleDb.OleDbDataAdapter()
    Dim MyCn As New OleDb.OleDbConnection()
    Dim sSQLString As String
    Dim bAddNew As Boolean
    Dim sReturn As String

    SaveUser = "Error"
    sReturn = Me.IsCorrect
    If Not sReturn = "OK" Then
    SaveUser = sReturn
    Exit Function
    End If

    If Me.UserID.ToString = Me.UserID.Empty.ToString Then
    sSQLString = "SELECT * FROM NWUSER"
    bAddNew = True
    Me.gUserID.NewGuid()
    Else
    sSQLString = "SELECT * FROM NWUSER WHERE USERID = '" & Me.UserID.ToString & "'"
    bAddNew = False
    End If

    Dim MyCo As New OleDb.OleDbCommand(sSQLString, MyCn)

    MyCn = db.CreateDBConnection()

    MyCo.CommandText = sSQLString
    MyCo.Connection = MyCn
    MyDa.SelectCommand = MyCo

    MyDs = db.CreateDataSet(sSQLString, "NWUSER")

    Dim MyDataRow As System.Data.DataRow
    If bAddNew Then
    MyDataRow = MyDs.Tables("NWUSER").NewRow
    Else
    MyDataRow = MyDs.Tables("NWUSER").Rows(0)
    MyDs.Tables("NWUSER").Rows(0).BeginEdit()
    End If

    MyDataRow("USERNAME") = Me.Username
    MyDataRow("PASSWORD") = Me.Password
    MyDataRow("USERID") = Me.gUserID

    If bAddNew Then
    MyDs.Tables("NWUSER").Rows.Add(MyDataRow)
    Else
    MyDs.Tables("NWUSER").Rows(0).EndEdit()
    End If

    Dim MyCb As OleDb.OleDbCommandBuilder = New OleDb.OleDbCommandBuilder(MyDa)

    MyCb.DataAdapter = MyDa

    MyDa.UpdateCommand = MyCb.GetUpdateCommand
    MyDa.InsertCommand = MyCb.GetInsertCommand

    Try
    MyDa.Update(MyDs.Tables("NWUSER"))
    SaveUser = "OK"
    Catch myOleDbException As System.Data.OleDb.OleDbException
    SaveUser = myOleDbException.Message
    Catch myInvalidOperationException As System.InvalidOperationException
    SaveUser = myInvalidOperationException.Message
    Finally
    MyCn.Close()
    End Try
    End Function

  2. #2
    Addicted Member
    Join Date
    Jun 2002
    Location
    Brisbane Australia
    Posts
    150

    syntax error

    I had problems with syntax errors as you are with datasets. I eventually tracked it down to using Access 'reserved words' - or what it thinks are reserved (I had Name and Date). try changing the field names in you r database say from password to zpassword and see if it solves the problem. This may not be the solution - just a suggestion

    BH

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width