| | |
Problem with update Access database using windows application front end
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2009
Posts: 11
Reputation:
Solved Threads: 0
I am trying to create an Inventory/Stock Control system as a windows application using vb.net with an Access database. This is my first time trying to use vb.net and im having difficulty making the application interactive. I am unable to update records to the database from the front end.
I am creating this application in Visual Studio 2008. The first problem that i would like to resolve is trying to update records to the database. My front-end consists of a datagrid at the top of the screen, which brings back all of the records from Qry_Categories. I then have text boxes below the datagrid that replicate the data in the grid above it. So which ever row is highlighted in the datagrid, that data is then automatically filled in the text boxes below it.
I then have an update button. To update a record the user will highlight the row in the datagrid, this information will then get filled in the text boxes. The user will make changes to any of the text boxes and then click on the 'Update' button. This is where I am having the problems. Please can someone provide me with the update button code that will work, as i have tried so many and none seem to work.
This is my code so far:
The Qry_Categories has the following field names:
PK_CategoryID
CategoryName
Description
I would really appreciate the help as it is urgent i get this application up and running. Thanks in advance
I am creating this application in Visual Studio 2008. The first problem that i would like to resolve is trying to update records to the database. My front-end consists of a datagrid at the top of the screen, which brings back all of the records from Qry_Categories. I then have text boxes below the datagrid that replicate the data in the grid above it. So which ever row is highlighted in the datagrid, that data is then automatically filled in the text boxes below it.
I then have an update button. To update a record the user will highlight the row in the datagrid, this information will then get filled in the text boxes. The user will make changes to any of the text boxes and then click on the 'Update' button. This is where I am having the problems. Please can someone provide me with the update button code that will work, as i have tried so many and none seem to work.
This is my code so far:
VB.NET Syntax (Toggle Plain Text)
Public Class Form1 Dim con As New OleDb.OleDbConnection Dim adp As OleDb.OleDbDataAdapter Dim cmd As OleDb.OleDbCommand = New OleDb.OleDbCommand(adp) Dim ds As New DataSet 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 'StockControlDataSet.LK_Categories' table. You can move, or remove it, as needed. Me.LK_CategoriesTableAdapter.Fill(Me.StockControlDataSet.LK_Categories) con.ConnectionString = ConfigurationManager.ConnectionStrings _ ("WRC_SMS_1.My.MySettings.StockControlConnectionString").ConnectionString.ToString() ' Fill the data grid viewer con.Open() cmd = New OleDb.OleDbCommand("Select * from Qry_Categories", con) adp = New OleDb.OleDbDataAdapter(cmd) adp.Fill(ds, "Qry_Categories") Me.LK_CategoriesDataGridView.DataSource = ds Me.LK_CategoriesDataGridView.DataMember = "Qry_Categories" End Sub Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click 'open(connection) con.Open() cmd.Connection = con Try cmd.CommandText = "UPDATE LK_Categories SET CategoryName = @CategoryName WHERE PK_CategoryID = @CatID" '"UPDATE LK_Categories SET CategoryName = @CategoryName WHERE PK_CategoryID = 16" Dim param As New OleDb.OleDbParameter Dim param2 As New OleDb.OleDbParameter 'add content txtProdName as parameter param.ParameterName = "@CategoryName" param.Value = txtbxCatName.Text() cmd.Parameters.Add(param) param2.ParameterName = "@CatID" param2.Value = txtCatID.Text cmd.Parameters.Add(param2) cmd.ExecuteNonQuery() MessageBox.Show("customer data successfully updated") Catch ex As Exception MessageBox.Show("cust data not updated because " _ & ex.Message) Finally 'close connection if it is open If (con.State = ConnectionState.Open) Then con.Close() End If End Try con.Close() End Sub
The Qry_Categories has the following field names:
PK_CategoryID
CategoryName
Description
I would really appreciate the help as it is urgent i get this application up and running. Thanks in advance
Welcome speedy gonzalos,
Do not use @ with parameter operand if database is Ms-Access.
Or use ? (anonymous)
Do not use @ with parameter operand if database is Ms-Access.
vb.net Syntax (Toggle Plain Text)
cmd.CommandText = "UPDATE LK_Categories SET CategoryName = mCategoryName WHERE PK_CategoryID =mCatID"
vb.net Syntax (Toggle Plain Text)
cmd.CommandText = "UPDATE LK_Categories SET CategoryName = ? WHERE PK_CategoryID =?"
Failure is not fatal, but failure to change might be. - John Wooden
•
•
Join Date: Jul 2009
Posts: 11
Reputation:
Solved Threads: 0
•
•
•
•
I am trying to create an Inventory/Stock Control system as a windows application using vb.net with an Access database. This is my first time trying to use vb.net and im having difficulty making the application interactive. I am unable to update records to the database from the front end.
I am creating this application in Visual Studio 2008. The first problem that i would like to resolve is trying to update records to the database. My front-end consists of a datagrid at the top of the screen, which brings back all of the records from Qry_Categories. I then have text boxes below the datagrid that replicate the data in the grid above it. So which ever row is highlighted in the datagrid, that data is then automatically filled in the text boxes below it.
I then have an update button. To update a record the user will highlight the row in the datagrid, this information will then get filled in the text boxes. The user will make changes to any of the text boxes and then click on the 'Update' button. This is where I am having the problems. Please can someone provide me with the update button code that will work, as i have tried so many and none seem to work.
This is my code so far:
VB.NET Syntax (Toggle Plain Text)
Public Class Form1 Dim con As New OleDb.OleDbConnection Dim adp As OleDb.OleDbDataAdapter Dim cmd As OleDb.OleDbCommand = New OleDb.OleDbCommand(adp) Dim ds As New DataSet 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 'StockControlDataSet.LK_Categories' table. You can move, or remove it, as needed. Me.LK_CategoriesTableAdapter.Fill(Me.StockControlDataSet.LK_Categories) con.ConnectionString = ConfigurationManager.ConnectionStrings _ ("WRC_SMS_1.My.MySettings.StockControlConnectionString").ConnectionString.ToString() ' Fill the data grid viewer con.Open() cmd = New OleDb.OleDbCommand("Select * from Qry_Categories", con) adp = New OleDb.OleDbDataAdapter(cmd) adp.Fill(ds, "Qry_Categories") Me.LK_CategoriesDataGridView.DataSource = ds Me.LK_CategoriesDataGridView.DataMember = "Qry_Categories" End Sub Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click 'open(connection) con.Open() cmd.Connection = con Try cmd.CommandText = "UPDATE LK_Categories SET CategoryName = @CategoryName WHERE PK_CategoryID = @CatID" '"UPDATE LK_Categories SET CategoryName = @CategoryName WHERE PK_CategoryID = 16" Dim param As New OleDb.OleDbParameter Dim param2 As New OleDb.OleDbParameter 'add content txtProdName as parameter param.ParameterName = "@CategoryName" param.Value = txtbxCatName.Text() cmd.Parameters.Add(param) param2.ParameterName = "@CatID" param2.Value = txtCatID.Text cmd.Parameters.Add(param2) cmd.ExecuteNonQuery() MessageBox.Show("customer data successfully updated") Catch ex As Exception MessageBox.Show("cust data not updated because " _ & ex.Message) Finally 'close connection if it is open If (con.State = ConnectionState.Open) Then con.Close() End If End Try con.Close() End Sub
The Qry_Categories has the following field names:
PK_CategoryID
CategoryName
Description
I would really appreciate the help as it is urgent i get this application up and running. Thanks in advance
I also removed this bit of the code from the top:
VB.NET Syntax (Toggle Plain Text)
' Fill the data grid viewer con.Open() cmd = New OleDb.OleDbCommand("Select * from Qry_Categories", con) adp = New OleDb.OleDbDataAdapter(cmd) adp.Fill(ds, "Qry_Categories") Me.LK_CategoriesDataGridView.DataSource = ds Me.LK_CategoriesDataGridView.DataMember = "Qry_Categories"
•
•
Join Date: Jul 2009
Posts: 11
Reputation:
Solved Threads: 0
The only problem now is that i can update only 1 record at a time. If i want to update 2 or more records at the same time, the changes will only show on the datagrid view but not update the database.
I will have to re-run the application each time i want to update a record. Can you tell me how i can make unlimited changes to the database withoout having to close and then re open the application?
I will have to re-run the application each time i want to update a record. Can you tell me how i can make unlimited changes to the database withoout having to close and then re open the application?
![]() |
Similar Threads
- how to update an access database using a textbox in vb (Visual Basic 4 / 5 / 6)
- Update Web.config from windows application (ASP.NET)
- update access database (C#)
- Front-end Java Software Engineer for Digital Video/Media Market Leader - Los Angeles (Software Development Job Offers)
- JSP access to MS Database. (JSP)
- Updating an Access database with a secondary form (VB.NET)
- Front-end Java Software Engineer for Digital Video/Media Market Leader (Software Development Job Offers)
- Problem with VB.NET and MS Access (VB.NET)
- simply generate user front end for mysql ? (MySQL)
Other Threads in the VB.NET Forum
| Thread Tools | Search this Thread |
.net .net2008 30minutes 2005 2008 access account arithmetic array basic binary bing button buttons center check code combobox component connectionstring crystalreport data database databasesearch datagrid datagridview date design dissertation dissertations dropdownlist excel fade file-dialog filter folder ftp generatetags google hardcopy images input insert intel internet mobile monitor ms net networking objects output panel passingparameters peertopeervideostreaming picturebox picturebox1 port position print printing problem problemwithinstallation project save searchbox searchvb.net select serial shutdown soap survey table tcp temperature text textbox timer timespan toolbox trim update updown user vb vb.net vb.netcode vb.netformclosing()eventpictureboxmessagebox vb2008 vbnet view visual visualbasic visualbasic.net visualstudio visualstudio2008 web winforms wpf year






