Results 1 to 4 of 4

Thread: [2005] Error Inserting records in mdb

  1. #1

    Thread Starter
    Member kashi_rock's Avatar
    Join Date
    Apr 2006
    Location
    Delhi (India)
    Posts
    55

    Question [2005] Error Inserting records in mdb

    hi all,
    I am inserting some data in an access database with folloing code:
    ---------------------------------------------------------------
    Private Sub Changepass_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    connection.Open()
    str = "Select * from login where Username = '" & Loginwindow.TextBox1.Text & "'"
    DA = New OleDb.OleDbDataAdapter(str, connection)
    DS = New DataSet
    DA.Fill(DS, "Table1")
    Dim DT As New DataTable
    DT.Columns.Add("Username", GetType(System.String))
    DT.Columns.Add("Password", GetType(System.String))
    DT.Columns.Add("Domintype", GetType(System.String))
    DT.Columns.Add("Employee", GetType(System.String))
    For Each drDSRow In DS.Tables("Table1").Rows()
    drNewRow = DT.NewRow()
    drNewRow("Username") = drDSRow("Username")
    drNewRow("Password") = drDSRow("Password")
    drNewRow("Domintype") = drDSRow("Domintype")
    drNewRow("Employee") = drDSRow("Employee")
    DT.Rows.Add(drNewRow)
    Next
    connection.Close()
    Dim username1 As String = DT.Rows(0)(0)
    paasword1 = DT.Rows(0)(1)
    Dim domin1 As String = DT.Rows(0)(2)
    Dim employee1 As String = DT.Rows(0)(3)
    End Sub
    --------------------
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    If paasword1 = TextBox1.Text Then
    Try
    connection.Open()
    str = "Insert into login (Username,Password,Domintype,Employee) values('" & TextBox3.Text & "','" & TextBox3.Text & "','" & TextBox3.Text & "','" & TextBox3.Text & "')"
    cmd = New OleDbCommand(str, connection)
    cmd.ExecuteNonQuery()
    Catch ex As Exception
    End Try
    connection.Close()
    Else : MsgBox("Password does not match. Please Try Again")
    End If
    End sub
    -------------------------------------------------
    I am able to insert records if I use another table insted of LOGIN but for login table I am helpless. Please suggest me where I am going wrong.

    Thx. n Rgds.
    Kashu

  2. #2

    Thread Starter
    Member kashi_rock's Avatar
    Join Date
    Apr 2006
    Location
    Delhi (India)
    Posts
    55

    Re: [2005] Error Inserting records in mdb

    Prgram is not showing any error message...

  3. #3
    Frenzied Member MrGTI's Avatar
    Join Date
    Oct 2000
    Location
    Ontario, Canada
    Posts
    1,277

    Post Re: [2005] Error Inserting records in mdb

    Try fixing your code so it:
    1. Actually shows you the error
    2. Tells you what the SQL statement looks like

    Try changing your code to look like this:
    VB Code:
    1. Try
    2.    connection.Open()
    3.    Dim sSQL as String = "Insert into login (Username,Password,Domintype,Employee) values('" & TextBox3.Text & "','" & TextBox3.Text & "','" & TextBox3.Text & "','" & TextBox3.Text & "')"
    4.    MsgBox(sSQL)
    5.    cmd = New OleDbCommand(sSQL, connection)
    6.    cmd.ExecuteNonQuery()
    7. Catch ex As Exception
    8.    MsgBox(ex.Message)
    9. End Try
    ~Peter


  4. #4

    Thread Starter
    Member kashi_rock's Avatar
    Join Date
    Apr 2006
    Location
    Delhi (India)
    Posts
    55

    Re: [2005] Error Inserting records in mdb

    hi MrGTI,
    I am getting error as following:

    Syntex Error in insert into statement.

    Rgds
    Kashu

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