469,643 Members | 2,061 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,643 developers. It's quick & easy.

Vb.Net "how to update rows in an mdb data source??"

hi everybody ,
I'm a beginner student in vb.net,and I'm working on a very small project as a homework,and I've some questions which I ought to search for their solutions via any source .
My question, I need to make an (Update )button in most of my VB forms,which enable me to update any row elements in the datasource in Access through each form ,
for example:
I've a form about CustomersData as (Cust_No,Cust_Name,Cust_Address,Cust_Phone...etc) when the user want to update one of the customer data ,s/he will display this customer data through the search method in the form and this customer data will appear in the textboxes in the CustomersData form,then s/he will start changing any element in this row then will press the update button to update the datasource which made in access (Cars.mdb)
I tried the following code which our trainer gave us ,but it doesn't work,she herself asked us to search for the solution.So,pleeeease help me. And if the update will be on a form related to more than one Table in the datasource ,is the code will be the same.With Thanks in advance..

Expand|Select|Wrap|Line Numbers
  1. Dim upd As New OleDbCommand
  2.         upd.CommandText = "update Customers set Cust_No= " & TextBox1.Text & ",Cust_Address='" & TextBox3.Text & "',Cust_Phone='" & TextBox4.Text & "'where Cust_Name='" & TextBox2.Text & "'"
  3.         upd.Connection = OleDbConnection1
  4.         OleDbConnection1.Open()
  5.         upd.ExecuteNonQuery()
  6.         OleDbConnection1.Close()
  7.         If TextBox2.Text = "" Then
  8.             MsgBox("There are no any data to update ,please retry.")
  9.         Else
  10.             MsgBox("Updating process done successfully")
  11.         End If
  12.     End Sub 
Also I tried this
Expand|Select|Wrap|Line Numbers
  1. Dim strcon As String
  3.         Try
  4.             strcon = "provider=microsoft.jet.oledb.4.0;data source=Cars.mdb "
  7.             Dim upd As New OleDbCommand
  8.            upd.CommandText = "update Customers set Cust_No= " & TextBox1.Text & ",Cust_Address='" & TextBox3.Text & "',Cust_Phone='" & TextBox4.Text & "'where Cust_Name='" & TextBox2.Text & "'"
  9.             upd.Connection = connn
  11.             connn.Open()
  13.             upd.ExecuteNonQuery()
  14.             connn.Close()
  15.             If TextBox2.Text = "" Then
  16.                 MsgBox("There are no any data to update ,please retry.")
  17.             Else
  20.                 upd.ExecuteNonQuery()
  21.                 MessageBox.Show("Updating process done successfully ")
  22.                 clear()
  23.                 connn.Close()
  24.             End If
  25.         Catch exp As Exception
  26.             MsgBox(exp.ToString)
  27.         End Try
May 24 '06 #1
0 4848

Post your reply

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

Similar topics

20 posts views Thread by Mark Harrison | last post: by
5 posts views Thread by maury | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.