I am working with multiple forms using an Access Database, VB.Net,
DataSet and OLEDB. Bacically the Add Member form is form 2, not the
opening form which is the Menu. If the Add Member form was the opening
form then I am able to add a new record, but for some reason I am
having trouble with the usage of mulitple forms and databases.
Imports System.Data
Public Class frmAddMember
Inherits System.Windows.Forms.Form
Dim inc As Integer
Dim MaxRows As Integer
Dim con As New OleDb.OleDbConnection
Dim ds As New DataSet
Dim da As OleDb.OleDbDataAdapter
Dim sql As String
Private Sub frmAddMember_Load(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles MyBase.Load
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source = C:\TravelAgents.mdb"
con.Open()
sql = "SELECT * FROM Members"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "TravelAgents")
con.Close()
End Sub
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAdd.Click
If inc <> -1 Then
Dim cb As New OleDb.OleDbCommandBuilder(da)
Dim dsNewRow As DataRow
dsNewRow = ds.Tables("TravelAgents").NewRow()
dsNewRow.Item("Member ID") = txtID.Text
dsNewRow.Item("Gender") = cmbGender.SelectedItem
dsNewRow.Item("Forename") = txtForename.Text
dsNewRow.Item("Surname") = txtSurname.Text
dsNewRow.Item("City") = cmbCity.SelectedItem
dsNewRow.Item("County") = cmbCounty.SelectedItem
dsNewRow.Item("Date of Birth") = txtDateOfBirth.Text
dsNewRow.Item("Phone Number") = txtPhoneNumber.Text
ds.Tables("TravelAgents").Rows.Add(dsNewRow)
da.Update(ds, "TravelAgents")
MsgBox("Sucess!!")
End If
End Sub
End Class
The only code on form1(Menu) is the navigational coding for the Add
button, am I supposed to put some code in when form1 is loading in
regards to the above. The File path is correct and the same code has
been used on another project which loads this form as the opening form
and it works fine, but this is no good to me. Any suggestions would be
very welcome and appreciated. Cheers.
BTW this is the error
An unhandled exception of type 'System.Data.OleDb.OleDbException'
occurred in system.data.dll
highlighting da.Update(ds, "TravelAgents") 2 1168
I am not sure what the problem is but you should put a Try ... Catch around
the da.Update(ds, "TravelAgents"). Then in the exeception msgbox the
"Message" property which should give details. If this is not enough check
if there is an InnerMessage. This is sometimes the real problem.
That should give you a hint.
LLoyd Sheen
<km*******@yahoo.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com... I am working with multiple forms using an Access Database, VB.Net, DataSet and OLEDB. Bacically the Add Member form is form 2, not the opening form which is the Menu. If the Add Member form was the opening form then I am able to add a new record, but for some reason I am having trouble with the usage of mulitple forms and databases. Imports System.Data
Public Class frmAddMember Inherits System.Windows.Forms.Form
Dim inc As Integer Dim MaxRows As Integer Dim con As New OleDb.OleDbConnection Dim ds As New DataSet Dim da As OleDb.OleDbDataAdapter Dim sql As String
Private Sub frmAddMember_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = C:\TravelAgents.mdb" con.Open() sql = "SELECT * FROM Members"
da = New OleDb.OleDbDataAdapter(sql, con) da.Fill(ds, "TravelAgents")
con.Close()
End Sub
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click If inc <> -1 Then
Dim cb As New OleDb.OleDbCommandBuilder(da) Dim dsNewRow As DataRow
dsNewRow = ds.Tables("TravelAgents").NewRow()
dsNewRow.Item("Member ID") = txtID.Text dsNewRow.Item("Gender") = cmbGender.SelectedItem dsNewRow.Item("Forename") = txtForename.Text dsNewRow.Item("Surname") = txtSurname.Text dsNewRow.Item("City") = cmbCity.SelectedItem dsNewRow.Item("County") = cmbCounty.SelectedItem dsNewRow.Item("Date of Birth") = txtDateOfBirth.Text dsNewRow.Item("Phone Number") = txtPhoneNumber.Text
ds.Tables("TravelAgents").Rows.Add(dsNewRow)
da.Update(ds, "TravelAgents")
MsgBox("Sucess!!")
End If
End Sub End Class
The only code on form1(Menu) is the navigational coding for the Add button, am I supposed to put some code in when form1 is loading in regards to the above. The File path is correct and the same code has been used on another project which loads this form as the opening form and it works fine, but this is no good to me. Any suggestions would be very welcome and appreciated. Cheers.
BTW this is the error
An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll highlighting da.Update(ds, "TravelAgents")
kmercer46,
Does your dataset's Insert command have square brackets around all the
column names that contain spaces, such as [Date of Birth]?
Column names that contain spaces must be enclosed in square brackets, and I
am not sure that the command builder includes them.
Kerry Moorman
"km*******@yahoo.com" wrote: I am working with multiple forms using an Access Database, VB.Net, DataSet and OLEDB. Bacically the Add Member form is form 2, not the opening form which is the Menu. If the Add Member form was the opening form then I am able to add a new record, but for some reason I am having trouble with the usage of mulitple forms and databases. Imports System.Data
Public Class frmAddMember Inherits System.Windows.Forms.Form
Dim inc As Integer Dim MaxRows As Integer Dim con As New OleDb.OleDbConnection Dim ds As New DataSet Dim da As OleDb.OleDbDataAdapter Dim sql As String
Private Sub frmAddMember_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = C:\TravelAgents.mdb" con.Open() sql = "SELECT * FROM Members"
da = New OleDb.OleDbDataAdapter(sql, con) da.Fill(ds, "TravelAgents")
con.Close()
End Sub
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click If inc <> -1 Then
Dim cb As New OleDb.OleDbCommandBuilder(da) Dim dsNewRow As DataRow
dsNewRow = ds.Tables("TravelAgents").NewRow()
dsNewRow.Item("Member ID") = txtID.Text dsNewRow.Item("Gender") = cmbGender.SelectedItem dsNewRow.Item("Forename") = txtForename.Text dsNewRow.Item("Surname") = txtSurname.Text dsNewRow.Item("City") = cmbCity.SelectedItem dsNewRow.Item("County") = cmbCounty.SelectedItem dsNewRow.Item("Date of Birth") = txtDateOfBirth.Text dsNewRow.Item("Phone Number") = txtPhoneNumber.Text
ds.Tables("TravelAgents").Rows.Add(dsNewRow)
da.Update(ds, "TravelAgents")
MsgBox("Sucess!!")
End If
End Sub End Class
The only code on form1(Menu) is the navigational coding for the Add button, am I supposed to put some code in when form1 is loading in regards to the above. The File path is correct and the same code has been used on another project which loads this form as the opening form and it works fine, but this is no good to me. Any suggestions would be very welcome and appreciated. Cheers.
BTW this is the error
An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll highlighting da.Update(ds, "TravelAgents")
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: cooldv |
last post by:
i am running a website on Windows 2000 server with ASP 3 webpages and
Access 2000 database. (with a hosting company)
traffic is slow at this time but expect to grow. lately i have been
reading...
|
by: George Stout |
last post by:
First off I do not know alot about writing queries to an Access
Database from an ASP page. This is why I need help.
I have an Events database for 6 colleges in our metro area. On the
homepage I...
|
by: nospammmer |
last post by:
Hello group,
I have a rather general but interesting inquiry that is related to PHP
and I hope this is the appropriate place to post it.
I'm looking for a way to improve dramatically the...
|
by: Marvin Libson |
last post by:
Hi All:
I am running DB2 UDB V7.2 with FP11. Platform is Windows 2000. I
have created a java UDF and trigger. When I update my database I get
the following error:
SQL1224N A database...
|
by: Alex |
last post by:
Hi all,
I've been running a db2 V8.1 databasle to store my radius server
accounting info
for a *long* time and have never had any problems with it.
Last week we had a power outage in our...
|
by: Bec |
last post by:
I'm in desperate need of your help..
I need to build an access database and have NO idea how to do this..
Not even where to start..
It IS for school, and am not asking anyone to do my...
|
by: Ann Marinas |
last post by:
Hi all,
I would like to ask for some help regarding separating the asp.net
webserver and the sql server.
I have created an asp.net application for a certain company. Initially,
we installed...
|
by: Wayne Smith |
last post by:
I've come up against a major headache that I can't seem to find a solution
for but I'm sure there must be a workaround and I would really be grateful
of any help.
I'm currently building a web...
|
by: surfrat_ |
last post by:
Hi,
I am having the following problems in getting Microsoft Visual Studio
2005 Professional to link to an Access .mdb
database. Please help me to sort this out.
Problem 1:
The Microsoft...
|
by: grace |
last post by:
i am wondering why my database retrieval becomes too slow...we set up
a new server (ubuntu, breezy badger) machine where we transferred all
our files from the old server.. Our new server uses Asus...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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...
|
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: 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: 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...
| |