Results 1 to 2 of 2

Thread: [RESOLVED] VB.NET Error: cmd.ExecuteNonQuery! Guide me

  1. #1
    Junior Member
    Join Date
    Dec 06
    Posts
    28

    Resolved [RESOLVED] VB.NET Error: cmd.ExecuteNonQuery! Guide me

    Hi GUys,

    Im getting error at cmd.ExecuteNonQuery. Kindly help me how to fix it..

    thanks in advance.


    Code:
    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
            Dim sqlinsert As String
            ' We use the INSERT statement which tells our program to add the information
            ' from the Forms Text fields into the Databases columns.
    
            sqlinsert = "INSERT INTO Contacts(FirstName, LastName, Address, CompanyName, CompanyAddress, PersonalAC, CompanyAC, PhoneNumber, Remarks, IDNum)" & _
          "VALUES(@FirstName, @LastName, @Address, @CompanyName, @CompanyAddress, @PersonalAC, @CompanyAC, @PhoneNumber, @Remarks, @IDNum)"
            Dim cmd As New OleDbCommand(sqlinsert, con1)
            ' This assigns the values for our columns in the DataBase.
            ' To ensure the correct values are written to the correct column
            cmd.Parameters.Add(New OleDbParameter("@FirstName", txtFirst.Text))
            cmd.Parameters.Add(New OleDbParameter("@LastName", txtLast.Text))
            cmd.Parameters.Add(New OleDbParameter("@Address", txtAddress.Text))
            cmd.Parameters.Add(New OleDbParameter("@CompanyName", txtCompanyN.Text))
            cmd.Parameters.Add(New OleDbParameter("@CompanyAddress", txtCompanyA.Text))
            cmd.Parameters.Add(New OleDbParameter("@PersonalAC", txtPersonalAC.Text))
            cmd.Parameters.Add(New OleDbParameter("@CompanyAC", txtCompanyAC.Text))
            cmd.Parameters.Add(New OleDbParameter("@PhoneNumber", txtPhone.Text))
            cmd.Parameters.Add(New OleDbParameter("@Remarks", txtRemarks.Text))
            cmd.Parameters.Add(New OleDbParameter("@IDNum", txtID.Text))
            ' This is what actually writes our changes to the DataBase.
            ' You have to open the connection, execute the commands and
            ' then close connection.
            con1.Open()
            cmd.ExecuteNonQuery()
            con1.Close()
            ' This are subs in Module1, to clear all the TextBoxes on the form
            ' and refresh the DataGridView on the MainForm to show our new records.
            ClearTextBox(Me)
            RefreshDGV()
            Me.Close()
        End Sub

  2. #2
    Frenzied Member make me rain's Avatar
    Join Date
    Sep 08
    Location
    india
    Posts
    1,637

    Re: VB.NET Error: cmd.ExecuteNonQuery! Guide me

    what the error says!
    The averted nuclear war
    My notes:
    Date&time
    PrOtect your PC. MSDN Functions .OOP LINUX forum
    .LINQ LINQ videous
    If some one helps you please rate them with out fail , forum doesn't expects any thing other than this

Posting Permissions

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