Please help! I have spent all weekend trying to solve this and its driving
me mad!
I have a form with a datagrid on. When I click button btnNew, the new row
appears in the datagrid but it does not update the back end access database.
The program continues to the messagebox to say that it has updated it
though. I've attached the relevant code but the main area is the Private
Sub btnNew_Click at the bottom of the posting
Thanks!
Public Class frmUsers
Inherits System.Windows.Forms.Form
Public cnn As New OleDb.OleDbConnection ' database connection string
Public strConn As String
Public cLoc As String
cLoc = "C:\Documents and Settings\dave.PROPENSITY\My Documents\Visual
Studio Projects\test login\login.mdb"
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & cLoc & _
"; Jet OLEDB:Database Password=flintstone"
Dim str1 As String = "Select * From Users"
Dim daUser As New OleDb.OleDbDataAdapter(str1, cnn)
Dim dsUser As New DataSet
Private Sub frmUsers_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
daUser.Fill(dsUser, "dtUser")
daUser.FillSchema(dsUser, SchemaType.Source, "Users")
dgUsers.DataSource = dsUser.Tables("dtUser")
Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnNew.Click
Dim drCurrent As DataRow
' Obtain a new DataRow object from the DataTable.
drCurrent = dsUser.Tables("dtuser").NewRow()
' Set the DataRow field values as necessary.
drCurrent("Username") = txtName.Text
drCurrent("Initials") = "George"
drCurrent("password") = "Johnson"
drCurrent("Disabled") = True
drCurrent("Passcode") = "1956 Arlington Pl."
'Pass that new object into the Add method of the DataTable.Rows collection.
dsUser.Tables("dtuser").Rows.Add(drCurrent)
MsgBox("Add was successful.")
'lets update the datasource
Dim strInsert As New OleDb.OleDbCommand
Dim prm As New OleDb.OleDbParameter
strInsert = cnn.CreateCommand
strInsert.CommandText = "Insert into Users (Username, Initials, password,
Disabled, Passcode) Values (@Username, @Initials, @password, @Disabled,
@Passcode)"
strInsert.CommandText = "Insert into Users (Username) Values (@Username)"
prm = strInsert.Parameters.Add("@Username", OleDb.OleDbType.VarWChar, 40,
"Username")
daUser.InsertCommand = strInsert
MsgBox("Updated database")
End Sub 2 1636
Dave:
Add this line of code in place of the line with the MsgBox:
Dim i as Integer = daUser.Update(dsUser, "dtUser")
MessageBox.Show(i.ToString, "Records Updated")
You aren't actually calling update and that's what needs to send the updates
to the db. I responded in ADO.NET too with a more thorough explanation, but
this alone should fix it barring any other errors like bad connection
strings or field names .
HTH,
Bill
"dave" <da**@dave.com> wrote in message
news:_C*********************@wards.force9.net... Please help! I have spent all weekend trying to solve this and its
driving me mad!
I have a form with a datagrid on. When I click button btnNew, the new row appears in the datagrid but it does not update the back end access
database. The program continues to the messagebox to say that it has updated it though. I've attached the relevant code but the main area is the Private Sub btnNew_Click at the bottom of the posting
Thanks!
Public Class frmUsers
Inherits System.Windows.Forms.Form
Public cnn As New OleDb.OleDbConnection ' database connection string
Public strConn As String
Public cLoc As String
cLoc = "C:\Documents and Settings\dave.PROPENSITY\My Documents\Visual Studio Projects\test login\login.mdb"
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & cLoc & _
"; Jet OLEDB:Database Password=flintstone"
Dim str1 As String = "Select * From Users"
Dim daUser As New OleDb.OleDbDataAdapter(str1, cnn)
Dim dsUser As New DataSet
Private Sub frmUsers_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
daUser.Fill(dsUser, "dtUser")
daUser.FillSchema(dsUser, SchemaType.Source, "Users")
dgUsers.DataSource = dsUser.Tables("dtUser")
Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNew.Click
Dim drCurrent As DataRow
' Obtain a new DataRow object from the DataTable.
drCurrent = dsUser.Tables("dtuser").NewRow() ' Set the DataRow field values as necessary.
drCurrent("Username") = txtName.Text
drCurrent("Initials") = "George"
drCurrent("password") = "Johnson"
drCurrent("Disabled") = True
drCurrent("Passcode") = "1956 Arlington Pl."
'Pass that new object into the Add method of the DataTable.Rows
collection. dsUser.Tables("dtuser").Rows.Add(drCurrent)
MsgBox("Add was successful.")
'lets update the datasource
Dim strInsert As New OleDb.OleDbCommand
Dim prm As New OleDb.OleDbParameter
strInsert = cnn.CreateCommand
strInsert.CommandText = "Insert into Users (Username, Initials, password, Disabled, Passcode) Values (@Username, @Initials, @password, @Disabled, @Passcode)"
strInsert.CommandText = "Insert into Users (Username) Values (@Username)"
prm = strInsert.Parameters.Add("@Username", OleDb.OleDbType.VarWChar, 40, "Username")
daUser.InsertCommand = strInsert
MsgBox("Updated database")
End Sub
Dave:
Add this line of code in place of the line with the MsgBox:
Dim i as Integer = daUser.Update(dsUser, "dtUser")
MessageBox.Show(i.ToString, "Records Updated")
You aren't actually calling update and that's what needs to send the updates
to the db. I responded in ADO.NET too with a more thorough explanation, but
this alone should fix it barring any other errors like bad connection
strings or field names .
HTH,
Bill
"dave" <da**@dave.com> wrote in message
news:_C*********************@wards.force9.net... Please help! I have spent all weekend trying to solve this and its
driving me mad!
I have a form with a datagrid on. When I click button btnNew, the new row appears in the datagrid but it does not update the back end access
database. The program continues to the messagebox to say that it has updated it though. I've attached the relevant code but the main area is the Private Sub btnNew_Click at the bottom of the posting
Thanks!
Public Class frmUsers
Inherits System.Windows.Forms.Form
Public cnn As New OleDb.OleDbConnection ' database connection string
Public strConn As String
Public cLoc As String
cLoc = "C:\Documents and Settings\dave.PROPENSITY\My Documents\Visual Studio Projects\test login\login.mdb"
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & cLoc & _
"; Jet OLEDB:Database Password=flintstone"
Dim str1 As String = "Select * From Users"
Dim daUser As New OleDb.OleDbDataAdapter(str1, cnn)
Dim dsUser As New DataSet
Private Sub frmUsers_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
daUser.Fill(dsUser, "dtUser")
daUser.FillSchema(dsUser, SchemaType.Source, "Users")
dgUsers.DataSource = dsUser.Tables("dtUser")
Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNew.Click
Dim drCurrent As DataRow
' Obtain a new DataRow object from the DataTable.
drCurrent = dsUser.Tables("dtuser").NewRow() ' Set the DataRow field values as necessary.
drCurrent("Username") = txtName.Text
drCurrent("Initials") = "George"
drCurrent("password") = "Johnson"
drCurrent("Disabled") = True
drCurrent("Passcode") = "1956 Arlington Pl."
'Pass that new object into the Add method of the DataTable.Rows
collection. dsUser.Tables("dtuser").Rows.Add(drCurrent)
MsgBox("Add was successful.")
'lets update the datasource
Dim strInsert As New OleDb.OleDbCommand
Dim prm As New OleDb.OleDbParameter
strInsert = cnn.CreateCommand
strInsert.CommandText = "Insert into Users (Username, Initials, password, Disabled, Passcode) Values (@Username, @Initials, @password, @Disabled, @Passcode)"
strInsert.CommandText = "Insert into Users (Username) Values (@Username)"
prm = strInsert.Parameters.Add("@Username", OleDb.OleDbType.VarWChar, 40, "Username")
daUser.InsertCommand = strInsert
MsgBox("Updated database")
End Sub
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Frnak McKenney |
last post by:
I'm using an in-core DataSet as an image of my application's
'database' (a multi-table Access97 mdb file). Updates are made to
the DataTables within the DataSet via forms with bound TextBoxes,...
|
by: jfathman |
last post by:
Hello,
We are considering a project that requires implementing a database
(Windows PC based) that would be shared by a small number of users.
The database would store events output by our...
|
by: Tc |
last post by:
Hi,
I was curious, I am thinking of writing an application that loads a dataset
from a database that resides on a server. The question I have is this, if
multiple copies of the app will be...
|
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...
|
by: Luis Esteban Valencia |
last post by:
Hello Everyone,
Iam an intermediate ASP.Net programmer and iam facing a challenging task.
I have a table in MS-SQL server database called 'Members'. The table has
following fields...
...
|
by: COHENMARVIN |
last post by:
I put the following code in my asp.net page:
dbPath = MapPath("/FBDB/db1_newport2003.mdb")
strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;"
strConnect = strConnect & "Data Source=" & dbpath & ";"...
|
by: cwbp17 |
last post by:
I'm having trouble updating individual datagrid cells.
Have two tables car_master (columns include Car_ID, YEAR,VEHICLE) and
car_detail (columns include Car_ID,PRICE,MILEAGE,and BODY);both tables...
|
by: r2destini |
last post by:
Hi Friends,
I am new to .Net. So I don't know much.
I am facing a problem in updating database through ADO.Net
I am creating the dataset and there is no problem in the updation and...
|
by: jonbartlam |
last post by:
Hi There
I'm not sure what exactly is going wrong here. I'm writing an application that retreives a table from a database (tbl_internalfaults) and updates it. (Actually, just the status column will...
|
by: zmickle |
last post by:
Excuse my noobness. I am managing an access database that is shared
by 4 users. Management does not want to use any technologies outside
of access for this application (no SQL Server, etc). I...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
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...
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
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...
| |