I've been doing a tutorial on http://www.homeandlearn.co.uk/NET/vbNet.html
and everything was fine until the part on databases and using dataAdapter.Update. I keep getting an error message. Here is the part that I have problems with
Private Sub btn登 _Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn登 .Click
Dim cb As New OleDb.OleDbCommandBuilder(dadapt)
dset.Tables("bihin").Rows(increment).Item(1) = txtCD.Text
dset.Tables("bihin").Rows(increment).Item(2) = txt名.Text
dset.Tables("bihin").Rows(increment).Item(3) = cmbbx備品 分.Text
dset.Tables("bihin").Rows(increment).Item(4) = cmbbx .Text
dset.Tables("bihin").Rows(increment).Item(5) = txtPN.Text
dset.Tables("bihin").Rows(increment).Item(6) = txtSN.Text
dset.Tables("bihin").Rows(increment).Item(7) = cmbbx購入先.Text
dset.Tables("bihin").Rows(increment).Item(8) = txt住所.Text
dset.Tables("bihin").Rows(increment).Item(9) = txtTEL.Text
dset.Tables("bihin").Rows(increment).Item(10) = txt日.Text
dset.Tables("bihin").Rows(increment).Item(11) = txt保障期間.Text
dset.Tables("bihin").Rows(increment).Item(12) = txt保障 容.Text
dset.Tables("bihin").Rows(increment).Item(13) = cmbbx保管場所.Text
dset.Tables("bihin").Rows(increment).Item(14) = cmbbx保管責任者.Text
dset.Tables("bihin").Rows(increment).Item(14) = txt備品 容.Text
dadapt.Update(dset)
MsgBox("updated")
The program will work if I leave out the dadapt.update(dset), but it does not make changes to the database, only to the dataset, so when I restart the program, it is back to the way it was. I want to be able to make changes to the database.

vb.net and updating database
avolites
Hello Venkat2Day
Thank you for your reply. I will look into your suggestions....here is more of more of my code...if that would be helpful...
I don't know much about programming so I have been using code that I don't completely understand like the CB...I just used what the tutorial says:
"To update the database, you need some extra code. Amend your code to this (the new lines are in bold, red text):
Dim cb As New OleDb.OleDbCommandBuilder(da)
ds.Tables("AddressBook").Rows(inc).Item(1) = txtFirstName.Text
ds.Tables("AddressBook").Rows(inc).Item(2) = txtSurname.Text
da.Update(ds, "AddressBook")
MsgBox("Data updated")"
(http://www.homeandlearn.co.uk/NET/nets12p9.html)
here is most of my code...
Public Class Form1
Inherits System.Windows.Forms.Form
Dim increment As Integer
Dim maxrows As Integer
Dim con As New OleDb.OleDbConnection()
Dim dset As New DataSet()
Dim dadapt As OleDb.OleDbDataAdapter
Dim sql As String
Private Sub navigateRecords() 'this is a sub that figures out which record
txtCD.Text = dset.Tables("bihin").Rows(increment).Item(1)
txt名.Text = dset.Tables("bihin").Rows(increment).Item(2)
cmbbx備品 分.Text = dset.Tables("bihin").Rows(increment).Item(3)
cmbbx .Text = dset.Tables("bihin").Rows(increment).Item(4)
txtPN.Text = dset.Tables("bihin").Rows(increment).Item(5)
txtSN.Text = dset.Tables("bihin").Rows(increment).Item(6)
cmbbx購入先.Text = dset.Tables("bihin").Rows(increment).Item(7)
txt住所.Text = dset.Tables("bihin").Rows(increment).Item(8)
txtTEL.Text = dset.Tables("bihin").Rows(increment).Item(9)
txt日.Text = dset.Tables("bihin").Rows(increment).Item(10)
txt保障期間.Text = dset.Tables("bihin").Rows(increment).Item(11)
txt保障 容.Text = dset.Tables("bihin").Rows(increment).Item(12)
cmbbx保管場所.Text = dset.Tables("bihin").Rows(increment).Item(13)
cmbbx保管責任者.Text = dset.Tables("bihin").Rows(increment).Item(14)
txt備品 容.Text = dset.Tables("bihin").Rows(increment).Item(15)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'loading the form
con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Administrator\My Documents\eileen\eileen's databases\bihin.mdb"
con.Open()
sql = "SELECT*FROM bihinTable"
dadapt = New OleDb.OleDbDataAdapter(sql, con)
dadapt.Fill(dset, "bihin")
con.Close()
maxrows = dset.Tables("bihin").Rows.Count 'counting the number of rows
End Sub
Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click 'moving to the next record
If increment <> maxrows - 1 Then
increment = increment + 1
navigateRecords()
Else
MsgBox("No more rows")
End If
End Sub
Private Sub btnPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrevious.Click 'moving to previous record
If increment > 0 Then
increment = increment - 1
navigateRecords()
Else
MsgBox("First record")
End If
End Sub
Private Sub btnFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFirst.Click 'first record
If increment <> 0 Then
increment = 0
navigateRecords()
End If
End Sub
Private Sub btnLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLast.Click 'last record
If increment <> maxrows - 1 Then
increment = maxrows - 1
navigateRecords()
End If
End Sub
Private Sub btn登 _Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn登 .Click 'place that the update doesn't work
Dim cb As New OleDb.OleDbCommandBuilder(dadapt)
dset.Tables("bihin").Rows(increment).Item(1) = txtCD.Text
dset.Tables("bihin").Rows(increment).Item(2) = txt名.Text
dset.Tables("bihin").Rows(increment).Item(3) = cmbbx備品 分.Text
dset.Tables("bihin").Rows(increment).Item(4) = cmbbx .Text
dset.Tables("bihin").Rows(increment).Item(5) = txtPN.Text
dset.Tables("bihin").Rows(increment).Item(6) = txtSN.Text
dset.Tables("bihin").Rows(increment).Item(7) = cmbbx購入先.Text
dset.Tables("bihin").Rows(increment).Item(8) = txt住所.Text
dset.Tables("bihin").Rows(increment).Item(9) = txtTEL.Text
dset.Tables("bihin").Rows(increment).Item(10) = txt日.Text
dset.Tables("bihin").Rows(increment).Item(11) = txt保障期間.Text
dset.Tables("bihin").Rows(increment).Item(12) = txt保障 容.Text
dset.Tables("bihin").Rows(increment).Item(13) = cmbbx保管場所.Text
dset.Tables("bihin").Rows(increment).Item(14) = cmbbx保管責任者.Text
dset.Tables("bihin").Rows(increment).Item(14) = txt備品 容.Text
dadapt.Update(dset, "bihin")
MsgBox("updated")
End Sub
Private Sub btn新規作成_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn新規作成.Click 'clearing a record
txtCD.Clear()
txt名.Clear()
txtPN.Clear()
txtSN.Clear()
txt住所.Clear()
txtTEL.Clear()
txt日.Clear()
txt保障期間.Clear()
txt保障 容.Clear()
txt備品 容.Clear()
End Sub
Afsoon
hi
this is kind of genral exception. and there is no specification. where is it accuring
try to debug the code and might be because of trying to update "autoincrement column" OR "primarykey column".
better you go with microsoft tutorial like VB.NET MCAD practice book. for practice purpose only.
rainwhenidie
Hi
1. you have declared CB. but where are you using it
2. is your dadapt having Insert, delete and update commands and proper connectionstring.
3. what is 'increment'
I think your code showing error in following line.
dset.Tables("bihin").Rows(increment).Item(1) = txtCD.Text
please try to debug it.
and please confirm this to
do you have any constrain in your database datatable.
ex: auto increment column.
rpark68
hello...thank you
I have made some changes but I'm still having problems. I guess one problem is that I am American and working in Japan and I cannot read the error messages but I will translate it the best that I can
error message:
'System.Data.OleDb.OleDbException' no handoru(handle) saretenai(not or isn't) reigai(exception or something abnormal) ga system.data.dll de hassei(occurrence or incidence) shimashita(happened)
MoFoQ
Hi
your tutorial is not a professional one. you need to have one dotnet professional for this.
any how this is my suggestion.
1. you dont need to open the con for dataAdapter
con.Open()
sql = "SELECT*FROM bihinTable"
dadapt = New OleDb.OleDbDataAdapter(sql, con)
dadapt.Fill(dset, "bihin")
con.Close()
2. you need to put this code like
dadapt = New OleDb.OleDbDataAdapter(sql, con)
dadapt.Fill(dset, "bihin")
maxrows = dset.Tables("bihin").Rows.Count
3. for update problem
dadapt.DeleteCommand = cb.GetDeleteCommand
dadapt.UpdateCommand = cb.GetUpdateCommand
dadapt.InsertCommand = cb.GetInsertCommand
dadapt.Update(dset, "bihin")
MsgBox("updated")
hope this may give you some output