i have written a vb.net coding for linkin my vb interface to my access database...its all the same....but some linking codes i wrote work,for other forms,but sum don work...
this is 1...its a form to add staff in my system

Imports System.Data
Imports System.Data.OleDb
Public Class Form1
    Dim ds As New DataSet
    Dim data As New OleDbDataAdapter
    Dim conn As New OleDbConnection
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\Group Project\Staff\Staff\bin\Debug\Blindz.mdb;User Id=;Password=;"

        data.SelectCommand = New OleDbCommand("SELECT * FROM Staff")
        data.SelectCommand.Connection = conn
        data.Fill(ds)

        data.InsertCommand = New OleDbCommand("INSERT INTO Staff(StaffName,BirthDate,Gender,Address,Phone,Position,StaffID,SystemPassword) VALUES(@StaffName,@BirthDate,@Gender,@Address,@Phone,@Position,@StaffID,@SystemPassword)")
        data.InsertCommand.Connection = conn
        data.InsertCommand.Parameters.Add("@StaffName", OleDbType.VarChar, 40, "StaffName")
        data.InsertCommand.Parameters.Add("@BirthDate", OleDbType.VarChar, 40, "BirthDate")
        data.InsertCommand.Parameters.Add("@Gender", OleDbType.VarChar, 40, "Gender")
        data.InsertCommand.Parameters.Add("@Address", OleDbType.VarChar, 40, "Address")
        data.InsertCommand.Parameters.Add("@Phone", OleDbType.VarChar, 40, "Phone")
        data.InsertCommand.Parameters.Add("@Pos", OleDbType.VarChar, 40, "Pos")
        data.InsertCommand.Parameters.Add("@StaffID", OleDbType.VarChar, 40, "StaffID")
        data.InsertCommand.Parameters.Add("@SysPassword", OleDbType.VarChar, 40, "SysPassword")
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim dr As DataRow

        dr = ds.Tables(0).NewRow()  'Gets a reference to a new row.
        dr("StaffName") = namebox.Text
        dr("BirthDate") = datebox.Value
        dr("Gender") = genbox.Text
        dr("Address") = addbox.Text
        dr("Phone") = phonebox.Text
        dr("Pos") = posbox.Text
        dr("StaffID") = id.Text
        dr("SysPassword") = syspass.Text

        ds.Tables(0).Rows.Add(dr)
        data.Update(ds)
        ds.AcceptChanges()
    End Sub
End Class

Thats my code above, my access fields are all text....coz i always get errors if i use other types.....can sum1 plz help me....i also noticed there are numerous ways to use ole.db to add to database....can sum1 tel me waths wrong??.....thank you....

Recommended Answers

All 2 Replies

do you get error, or the program run but no change made to database or what ?

i get an error,syntax error in INSERT INTO STATEMENT....i get tht manal....any idea?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.