473,387 Members | 1,549 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Why can't I update all the fields in my database via vb.net

1
There are 4 fields in my database(exlcuding the primary key)...only 3 fields can be successfully updated. the "Section" field returns an error pointing to da.Update(ds, "moreforengineers")?

the following is my code

Public Class Register
Dim cb As New OleDb.OleDbCommandBuilder(da)
Dim dsNewRow As DataRow
Dim inc As Integer
Dim MaxRows As Integer
Dim con As New OleDb.OleDbConnection
Dim dbProvider As String
Dim dbSource As String
Dim ds As New DataSet
Dim da As OleDb.OleDbDataAdapter
Dim sql As String
Private Sub NavigateRecords()
SectionTextBox.Text = ds.Tables("moreforengineers").Rows(inc).Item("Sect ion")
LastNameTextBox.Text = ds.Tables("moreforengineers").Rows(inc).Item("LNam e")
FirstNameTextBox.Text = ds.Tables("moreforengineers").Rows(inc).Item("FNam e")
MobileNoTextBox.Text = ds.Tables("moreforengineers").Rows(inc).Item("Mobi leNo")
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'MoreforengineersDataSet.Register' table. You can move, or remove it, as needed.

ClearButton.Enabled = False
RegisterButton.Enabled = False

loaddb()

End Sub
Private Sub loaddb()
con.Close()
Me.RegisterTableAdapter.Fill(Me.MoreforengineersDa taSet.Register)

dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
dbSource = "Data Source = C:\Users\Geraldine\Documents\Visual Studio 2010\Projects\moreforengineers\moreforengineers\mo reforengineers.mdb"

con.ConnectionString = dbProvider & dbSource
con.Open()


sql = "SELECT * FROM Register"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "moreforengineers")

inc = 0
NavigateRecords()

con.Close()

MaxRows = ds.Tables("moreforengineers").Rows.Count

End Sub


Private Sub RegisterButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RegisterButton.Click
RegisterButton.Enabled = True
AddButton.Enabled = False
UpdateButton.Enabled = False
DeleteButton.Enabled = False

If inc <> -1 Then

Dim cb As New OleDb.OleDbCommandBuilder(da)
Dim dsNewRow As DataRow

dsNewRow = ds.Tables("moreforengineers").NewRow()
dsNewRow.Item("Section") = SectionTextBox.Text
dsNewRow.Item("LName") = LastNameTextBox.Text
dsNewRow.Item("FName") = FirstNameTextBox.Text
dsNewRow.Item("MobileNo") = MobileNoTextBox.Text

ds.Tables("moreforengineers").Rows.Add(dsNewRow)
loaddb()
da.Update(ds, "moreforengineers")

MsgBox("New Record added to the Database")

AddButton.Enabled = True
UpdateButton.Enabled = True
DeleteButton.Enabled = True
CancelButton.Enabled = True

End If
End Sub

Private Sub ClearButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearButton.Click
SectionTextBox.Clear()
FirstNameTextBox.Clear()
LastNameTextBox.Clear()
MobileNoTextBox.Clear()
End Sub


Private Sub NextButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NextButton.Click
If inc <> MaxRows - 1 Then
inc = inc + 1
NavigateRecords()
Else
MsgBox("No More Rows")
End If
End Sub

Private Sub PreviousButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PreviousButton.Click
If inc > 0 Then
inc = inc - 1
NavigateRecords()
ElseIf inc = -1 Then
MsgBox("No Records Yet")
ElseIf inc = 0 Then
MsgBox("First Record")
End If

End Sub

Private Sub LastButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LastButton.Click
If inc <> MaxRows - 1 Then
inc = MaxRows - 1
NavigateRecords()
End If
End Sub

Private Sub FirstButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FirstButton.Click
If inc <> 0 Then
inc = 0
NavigateRecords()
End If

End Sub

Private Sub RegisterBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.Validate()
Me.RegisterBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.Moreforenginee rsDataSet)

End Sub

Private Sub UpdateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UpdateButton.Click
Dim cb As New OleDb.OleDbCommandBuilder(da)


ds.Tables("moreforengineers").Rows(inc).Item("Sect ion") = SectionTextBox.Text
ds.Tables("moreforengineers").Rows(inc).Item("LNam e") = LastNameTextBox.Text
ds.Tables("moreforengineers").Rows(inc).Item("FNam e") = FirstNameTextBox.Text
ds.Tables("moreforengineers").Rows(inc).Item("Mobi leNo") = MobileNoTextBox.Text

da.Update(ds, "moreforengineers")

MsgBox("Data updated")

loaddb()

End Sub

Private Sub AddButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddButton.Click
RegisterButton.Enabled = True
AddButton.Enabled = False
UpdateButton.Enabled = False
DeleteButton.Enabled = False
ClearButton.Enabled = True

SectionTextBox.Clear()
FirstNameTextBox.Clear()
LastNameTextBox.Clear()
MobileNoTextBox.Clear()

End Sub

Private Sub CancelButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CancelButton.Click
RegisterButton.Enabled = False
AddButton.Enabled = True
UpdateButton.Enabled = True
DeleteButton.Enabled = True
ClearButton.Enabled = False
CancelButton.Enabled = False

inc = 0
NavigateRecords()

End Sub

Private Sub DeleteButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DeleteButton.Click
Dim cb As New OleDb.OleDbCommandBuilder(da)

If MessageBox.Show("Do you really want to Delete this Record?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = DialogResult.No Then

MsgBox("Operation Cancelled")
Exit Sub

Else


ds.Tables("moreforengineers").Rows(inc).Delete()
MaxRows = MaxRows - 1

inc = 0
loaddb()
da.Update(ds, "moreforengineers")

End If

End Sub
End Class
Sep 9 '10 #1
1 1995
mzmishra
390 Expert 256MB
What exception or error you are getting
Sep 10 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Jim S. | last post by:
I'm having a horrible time simply inserting the date in a MySQL database through a Visual Basic program. I have a table, called "ORDERS"; "ID" is the primary key. I'm trying the insert the date,...
9
by: Pam Ammond | last post by:
I need the code to update the database when Save is clicked and a text field has changed. This should be very easy since I used Microsoft's wizards for the OleDBAdapter and OleDBConnection, and...
0
by: zhaoJian | last post by:
Here it is my code ,but it can't update the database.How to do it ? In _UpdateUnit event, I can not get the original value to @Original_UnitID,so I set a hidden column named LabelKey.But It...
3
by: Johannes Matlaisane | last post by:
Plz help I have using VB.Net window - my application doesn't want to updated the databas, the only row that it updated is of the type "Int - which has the identity increment of one, sql update...
1
by: A_StClaire_ | last post by:
hi all, I am using a GridView bound to an ObjectDataSource. edit and delete functionality has been enabled. my ObjectDataSource is tied to a TableAdapter that accesses three stored procedures...
3
by: EForbes | last post by:
Not an expert so I need some help. I have this function that I am trying to run. The function is to compine two tables, comcare a field in the tables and update the one table if te fields are not...
7
by: Daedalus | last post by:
Hello all you brillaint people who might be able to help me. I've recently become treasurer for a small club and need to create a membership database. Now I'm almost a complete newbie at...
5
by: Luqman | last post by:
I added new rows to the GridView with the following code. I am using SqlDataSource and Sql Server 2000 Northwind Database Customers table. Dim sqlarg As New DataSourceSelectArguments Dim dv...
5
by: Ferasse | last post by:
Hi, I'm an occasional Ms-Access developer, so there is still a lot of stuff that I don't get... Right now, I'm working on a database that stores contractual information. One of the form that...
2
by: mariaz | last post by:
Hello, I am creating a project where I parse an xml page (feed from a website) in a javabean file and I insert the parsed data in a mysql database. I want this data that gets inserted into the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.