Results 1 to 2 of 2

Thread: Help with Insert statments

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2001
    Posts
    41

    Help with Insert statments

    Hi

    Finnaly thks to al the ppl that look or reply my other questions and with luck I have made it this far with my program ^^

    now i'm trying to insert value into my database
    the only problem that is stoping me is that, in one of the coloumn (UserID) the values are set to auto number. as u can see i'm using the insert statment from the vb.net database wizzard and simply passing the values to the created insert statments.

    So how can i add the last bit of code so that i can insert everything into my database?


    Me.OleDbDataAdapter2.InsertCommand.Parameters("Name").Value = Me.regFullNameTxt.Text()
    Me.OleDbDataAdapter2.InsertCommand.Parameters("LoginPassword").Value = Me.regPwdTxt.Text
    Me.OleDbDataAdapter2.InsertCommand.Parameters("LoginName").Value = Me.regLogNameTxt.Text

    Me.OleDbDataAdapter2.InsertCommand.ExecuteNonQuery()

  2. #2

    Thread Starter
    Member
    Join Date
    Jul 2001
    Posts
    41
    Here is my solution for the problem I had >.<
    i'm not sure if its the best way to do it. If it doing what I wanted to do then, it is fine by me ^^.

    Dim UserIDNo As Integer
    Dim objReader As OleDb.OleDbDataReader

    'find the unique userID
    OleDbCommand2.CommandText = "select count(*) from Users "
    objReader = OleDbCommand2.ExecuteReader()


    If Not objReader.Read() Then
    'couldn't get the User ID
    MsgBox("There is an error trying to get the UserID value", , "OleDB reader error")

    End If

    UserIDNo = objReader(0) + 1

    objReader.Close()


    'Insert into database
    Me.OleDbDataAdapter2.InsertCommand.Parameters("Name").Value = Me.regFullNameTxt.Text()
    Me.OleDbDataAdapter2.InsertCommand.Parameters("LoginPassword").Value = Me.regPwdTxt.Text()
    Me.OleDbDataAdapter2.InsertCommand.Parameters("LoginName").Value = Me.regLogNameTxt.Text()

    OleDbCommand2.CommandText = "select Users.UserID from Users where " & "UCase(LoginName) = '" & _
    UCase(Me.regLogNameTxt.Text) & "' "


    Me.OleDbDataAdapter2.InsertCommand.Parameters("UserID").Value = UserIDNo

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