473,379 Members | 1,255 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,379 software developers and data experts.

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
  2.  
  3.         Try
  4.             strcon = "provider=microsoft.jet.oledb.4.0;data source=Cars.mdb "
  5.  
  6.  
  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
  10.  
  11.             connn.Open()
  12.  
  13.             upd.ExecuteNonQuery()
  14.             connn.Close()
  15.             If TextBox2.Text = "" Then
  16.                 MsgBox("There are no any data to update ,please retry.")
  17.             Else
  18.  
  19.  
  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 4981

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

Similar topics

1
by: Pete Mahoney | last post by:
Ok I use a textarea to store data input by the user, and then upon them clicking the submit button I store this data to a database. The problem is once the user inputs too much data (about 3...
4
by: RK | last post by:
Hi, In my application, I need to copy data from an Excel file into a SQL table. The article related to this can be found at http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B306572 ...
8
by: RC | last post by:
In my Access 2002 form, I have a combo box and on the AfterUpdate event I use DoCmd.RunSQL ("UPDATE .... to update records in a table. When it starts to run I get a message "You are about to...
3
by: beta | last post by:
Hello everyone, I need some help here. If anyone has encountered this, knidly give me your advice. I have a command button (Command0) and a listbox (List1). Upon clicking the command button,...
20
by: Mark Harrison | last post by:
So I have some data that I want to put into a table. If the row already exists (as defined by the primary key), I would like to update the row. Otherwise, I would like to insert the row. I've...
1
by: H5N1 | last post by:
hi there the topic says it all. I have a outer join select statement in tableadapter that populates GridView, I want to make it updatetable, so I need to provide an update command for table...
4
by: JDC | last post by:
Hi all, I'm using ObjectDataSource to select & update records. I have a "RecordDetails" class which encapsulates the row I want to update, and so it contains the fields I want to update and also...
7
by: Brave | last post by:
I am hoping for a code example of how to do this, and hopefully it will help me to see an easy way to code what seems to be a huge monster. I need to create a form that has two pulldown menues...
5
by: maury | last post by:
Hello, I have a DB table with data filled from a weather sensor probe, I have one row every 10 minutes and the data fields is not in DateTime format but in string format: yyyyMMddHHmm So for...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.