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 1648
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: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |