1,105,333 Community Members

vb.net error not adding

Member Avatar
bantex07
Light Poster
28 posts since Feb 2010
Reputation Points: -2 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

here is may code the error is .ExecuteNonQuery()
thx for helping

Imports System.Data.OleDb
Public Class registration


    Private Sub registration_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim connectionstring As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|datadirectory|\db1.accdb; persist security info = false"


        conn.ConnectionString = connectionstring

        If conn.State = ConnectionState.Closed Then
            MsgBox("open")
        Else
            MsgBox("close")
        End If

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            Dim SqlQuery As String = "INSERT INTO tblstu (fname,lname,grade)VALUES('" & TextBox1.Text & "' , '" & TextBox2.Text & "' ,'" & TextBox3.Text & "');"
            Dim SqlCommand As New OleDbCommand

            With SqlCommand
                .CommandText = SqlQuery
                .Connection = conn
                .ExecuteNonQuery()
            End With
            MsgBox("One record Successfully Added..")
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub
End Class
Member Avatar
Reverend Jim
Noli mentula
5,393 posts since Aug 2010
Reputation Points: 744 [?]
Q&As Helped to Solve: 643 [?]
Skill Endorsements: 51 [?]
Moderator
Featured
 
0
 

ExecuteNonQuery()

is not an error. It is a statement. Please post the text of the error message. Because the source of the error is likely the query, please also post the value of SqlQuery. It would also help to know the field types of your database table. For example, if grade is a string then the query may be OK. If grade is a number then you shouldn't have single quotes around the value for grade.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: