How To I Add A Record In A Database In VB?

casualrich

Member
Joined
Dec 17, 2008
Messages
12
Programming Experience
1-3
hi as some of you know i have this assignment where i have had to attach a database into a vb file I have now done this bit

but now i need to add a new record into table when VB is running

but im not sure on how to do it

here is my code
VB.NET:
    Private Sub butadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butadd.Click
        Dim myconnection As OleDb.OleDbConnection
        Dim strSQL As String

        'this is using parameters 
        strSQL = "INSERT INTO Engineers " & _
        " (EngineerNO, Surname , Firstname, Mobileno) "
 
You create an OleDbCommand, assign you're SQL code to its CommandText property, add a parameter for each value you want to insert, then call its ExecuteNonQuery method. You'll need to open your connection first and close it again afterwards. You should start by reading the MSDN documentation for the OleDbCommand class. There are also plenty of ADO.NET tutorials on the Web.
 

Latest posts

Back
Top