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 1642
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: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |