DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   VB.NET (http://www.daniweb.com/forums/forum58.html)
-   -   help in my linkin.... (http://www.daniweb.com/forums/thread149137.html)

mugun Oct 4th, 2008 3:25 pm
help in my linkin....
 
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....

manal Oct 4th, 2008 3:30 pm
Re: help in my linkin....
 
do you get error, or the program run but no change made to database or what ?

mugun Oct 5th, 2008 2:11 am
Re: help in my linkin....
 
i get an error,syntax error in INSERT INTO STATEMENT....i get tht manal....any idea?


All times are GMT -4. The time now is 7:13 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC