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.Dim upd As New OleDbCommand
upd.CommandText = "update Customers set Cust_No= " & TextBox1.Text & ",Cust_Address='" & TextBox3.Text & "',Cust_Phone='" & TextBox4.Text & "'where Cust_Name='" & TextBox2.Text & "'"
upd.Connection = OleDbConnection1
OleDbConnection1.Open()
upd.ExecuteNonQuery()
OleDbConnection1.Close()
If TextBox2.Text = "" Then
MsgBox("There are no any data to update ,please retry.")
Else
MsgBox("Updating process done successfully")
End If
End Sub
Also I tried this
Dim strcon As String
Try
strcon = "provider=microsoft.jet.oledb.4.0;data source=Cars.mdb "
Dim upd As New OleDbCommand
upd.CommandText = "update Customers set Cust_No= " & TextBox1.Text & ",Cust_Address='" & TextBox3.Text & "',Cust_Phone='" & TextBox4.Text & "'where Cust_Name='" & TextBox2.Text & "'" upd.Connection = connn
connn.Open()
connn.Close()
MessageBox.Show("Updating process done successfully ")
clear()
Catch exp As Exception
MsgBox(exp.ToString)
End Try