Results 1 to 2 of 2

Thread: Problem insert into database

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2003
    Posts
    219

    Question Problem insert into database

    Will anyone tell me what's wrong with the following insert sub routin into my mdb database file?

    Public Shared Sub usrProfileInsert(ByVal comboSerial As ComboBox, ByVal txtCpName As TextBox, ByVal txtUsrName As TextBox, ByVal txtIPAddress As TextBox, ByVal txtSpeed As TextBox, ByVal txtMemory As TextBox, ByVal txtHD1 As TextBox, ByVal txtHD2 As TextBox, ByVal txtHDType As TextBox, ByVal txtOS As TextBox)
    Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & mdbPath
    Dim strSerial, strCompName, strUser, strIPAddress, strHDType, strOS As String
    Dim strSpeed, strMemory, strHD1, strHD2 As Long
    Dim cn As New OleDbConnection(strConn)
    cn.Open()
    Dim cmd As OleDbCommand = cn.CreateCommand()
    strSerial = comboSerial.Text
    strCompName = txtCpName.Text
    strUser = txtUsrName.Text
    strIPAddress = txtIPAddress.Text
    strSpeed = CInt(txtSpeed.Text)
    strMemory = CInt(txtMemory.Text)
    strHD1 = CDec(txtHD1.Text)
    strHD2 = CDec(txtHD2.Text)
    strHDType = txtHDType.Text
    strOS = txtOS.Text

    Try
    cmd.CommandText = "INSERT INTO UserProfile (DPSerial, ComputerName, User, IP_Address, Speed, Memory, HD1, HD2, HDType, OS) VALUES ('" & strSerial & "', '" & strCompName & "', '" & strUser & "', '" & strIPAddress & "', " & strSpeed & ", " & strMemory & ", " & strHD1 & ", " & strHD2 & ", '" & strHDType & "', '" & strOS & "')"

    Dim intRecordAffected As Integer = cmd.ExecuteNonQuery()
    If intRecordAffected = 1 Then
    MsgBox("Insert Successful")
    End If
    cn.Close()
    Catch ex As Exception
    MessageBox.Show(ex.Message)
    End Try
    End Sub
    The error I received is Syntax error in INSERT INTO statement.

    Many thanks in advance!

    ljCharlie

  2. #2
    New Member
    Join Date
    Apr 2003
    Location
    Miami
    Posts
    12

    Single quotes..

    Try putting single quotes for all of the values...I think that's the problem

    Code:
    cmd.CommandText = "INSERT INTO UserProfile (DPSerial, ComputerName, User, IP_Address, Speed, Memory, HD1, HD2, HDType, OS) VALUES ('" & strSerial & "', '" & strCompName & "', '" & strUser & "', '" & strIPAddress & "', " & strSpeed & "','" & strMemory & "', '" & strHD1 & "', '" & strHD2 & ", '" & strHDType & "', '" & strOS & "')"

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