473,763 Members | 4,808 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

using strongly typed dataset update problem

I get stuck to write an update, insert and delete command, i am looking for
some help to start

Whats the best way to update 2 tables toe the database (Access)
below my code used to load my data.(2 tables)
Do someone has a good sample code to help me?

Many thanks in advance,
Marc.

'************be gin code*********** ****
Imports System
Imports System.Data
Imports system.Data.ole db

Public Class frmPostcodesTyp edDS

Inherits System.Windows. Forms.Form

Dim strPath As String = "C:\AADatabases \BeActionData.m db"
Dim strCnBeActionDa ta As String = "provider=micro soft.jet.oledb. 4.0;
Data Source=" & strPath

Dim daActionData As OleDbDataAdapte r
'Dim mydtPostcodes As dtPostcodes = New dtPostcodes()
Dim cnBeActionData As New OleDbConnection (strCnBeActionD ata)

Dim dsLandenPostcod es As New DataSet
Dim da1 As New OleDbDataAdapte r
Dim da2 As New OleDbDataAdapte r

Dim dt1 As New DataTable
Dim dt2 As New DataTable
Private Sub frmPostcodes_Lo ad(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Call LoadPostcodes()
End Sub
Sub LoadPostcodes()

' Dim dsLandenPostcod es As New DataSet
Dim dt1 As New DataTable
Dim dt2 As New DataTable
dsLandenPostcod es.Tables.Add(d t1)
dsLandenPostcod es.Tables.Add(d t2)
Dim da1 As New OleDbDataAdapte r("Select * from [tblLanden]",
cnBeActionData)
Dim da2 As New OleDbDataAdapte r("Select * from
[tblLandenPostco des]", cnBeActionData)

da1.FillSchema( dt1, SchemaType.Mapp ed)
da2.FillSchema( dt2, SchemaType.Mapp ed)

Dim rel As New DataRelation("F KPostcLanden_Po stcodes",
dsLandenPostcod es.Tables(0).Co lumns("Landcode "),
dsLandenPostcod es.Tables(1).Co lumns("Landcode "))
dsLandenPostcod es.Relations.Ad d(rel)

Dim bsPostcodeLande n As New BindingSource
bsPostcodeLande n.DataMember = dsLandenPostcod es.Tables(0).Ta bleName
bsPostcodeLande n.DataSource = dsLandenPostcod es

Dim bsPostcodes As New BindingSource
bsPostcodes.Dat aSource = bsPostcodeLande n
bsPostcodes.Dat aMember = "FKPostcLanden_ Postcodes"

da1.Fill(dt1)
da2.Fill(dt2)

Me.dgvPostcodeL anden.DataSourc e = bsPostcodeLande n
Me.dgvPostcodes .DataSource = bsPostcodes
End Sub
'************Ei nde code*********** ****
Oct 4 '06 #1
2 2339
Hi Mark,

Here is a sample I just wrote:

Imports System.Data.Ole Db
Public Class Form2
Dim conn As OleDbConnection , da As OleDbDataAdapte r, ds As DataSet
Private Sub Form2_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
conn = New OleDbConnection
conn.Connection String = "provider=micro soft.jet.oledb. 4.0; Data
Source = db2test.mdb"
da = New OleDbDataAdapte r
ds = New DataSet
da.SelectComman d = New OleDbCommand
da.SelectComman d.Connection = conn
da.SelectComman d.CommandType = CommandType.Tex t
da.SelectComman d.CommandText = "Select * from Table1"
da.Fill(ds, "tbl1")
dgrv1.DataSourc e = ds.Tables(0)
End Sub

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
da.UpdateComman d = New OleDbCommand
da.UpdateComman d.Connection = conn
da.UpdateComman d.CommandType = CommandType.Tex t
da.UpdateComman d.CommandText = "Update Table1 Set Field3 = 'aaa'
where ID = 3"
conn.Open()
da.UpdateComman d.ExecuteNonQue ry()
'da.Update(ds, "tbl1") '--<<---had to use ExecuteNonQuery since this
didn't run
ds.Clear()
da.Fill(ds, "tbl1")
dgrv1.DataSourc e = ds.Tables(0)
conn.Close()
MessageBox.Show ("Updated")
End Sub
End Class

the first routine loads data from a table in an Access mdb. The second
routine updates the table. The only thing is that I couldn't get the
da.Update thing to work (like it does with sql server). So I used
da.UpdateComman d.ExecuteNonQue ry which did work. The only thing is that you
have to open and close the connection yourself where usually the dataAdapter
takes care of that automatically.

Rich
"Scotty" wrote:
I get stuck to write an update, insert and delete command, i am looking for
some help to start

Whats the best way to update 2 tables toe the database (Access)
below my code used to load my data.(2 tables)
Do someone has a good sample code to help me?

Many thanks in advance,
Marc.

'************be gin code*********** ****
Imports System
Imports System.Data
Imports system.Data.ole db

Public Class frmPostcodesTyp edDS

Inherits System.Windows. Forms.Form

Dim strPath As String = "C:\AADatabases \BeActionData.m db"
Dim strCnBeActionDa ta As String = "provider=micro soft.jet.oledb. 4.0;
Data Source=" & strPath

Dim daActionData As OleDbDataAdapte r
'Dim mydtPostcodes As dtPostcodes = New dtPostcodes()
Dim cnBeActionData As New OleDbConnection (strCnBeActionD ata)

Dim dsLandenPostcod es As New DataSet
Dim da1 As New OleDbDataAdapte r
Dim da2 As New OleDbDataAdapte r

Dim dt1 As New DataTable
Dim dt2 As New DataTable
Private Sub frmPostcodes_Lo ad(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Call LoadPostcodes()
End Sub
Sub LoadPostcodes()

' Dim dsLandenPostcod es As New DataSet
Dim dt1 As New DataTable
Dim dt2 As New DataTable
dsLandenPostcod es.Tables.Add(d t1)
dsLandenPostcod es.Tables.Add(d t2)
Dim da1 As New OleDbDataAdapte r("Select * from [tblLanden]",
cnBeActionData)
Dim da2 As New OleDbDataAdapte r("Select * from
[tblLandenPostco des]", cnBeActionData)

da1.FillSchema( dt1, SchemaType.Mapp ed)
da2.FillSchema( dt2, SchemaType.Mapp ed)

Dim rel As New DataRelation("F KPostcLanden_Po stcodes",
dsLandenPostcod es.Tables(0).Co lumns("Landcode "),
dsLandenPostcod es.Tables(1).Co lumns("Landcode "))
dsLandenPostcod es.Relations.Ad d(rel)

Dim bsPostcodeLande n As New BindingSource
bsPostcodeLande n.DataMember = dsLandenPostcod es.Tables(0).Ta bleName
bsPostcodeLande n.DataSource = dsLandenPostcod es

Dim bsPostcodes As New BindingSource
bsPostcodes.Dat aSource = bsPostcodeLande n
bsPostcodes.Dat aMember = "FKPostcLanden_ Postcodes"

da1.Fill(dt1)
da2.Fill(dt2)

Me.dgvPostcodeL anden.DataSourc e = bsPostcodeLande n
Me.dgvPostcodes .DataSource = bsPostcodes
End Sub
'************Ei nde code*********** ****
Oct 4 '06 #2
Hi Rich,

Thanks for your answer
I have tested your sample and works fine,
But this is not realy my question,

As sample i have a database with 2 tables like tblCountry and
tblCountryPostc odes
If you like I send you this evening the Access database and the sample
programm (vbnet2005) as sample to use?

I like to fill in new items the form textbox and datagridview to update
them.

Many thanks,

Marc,
Belgium

"Rich" <Ri**@discussio ns.microsoft.co mschreef in bericht
news:A8******** *************** ***********@mic rosoft.com...
Hi Mark,

Here is a sample I just wrote:

Imports System.Data.Ole Db
Public Class Form2
Dim conn As OleDbConnection , da As OleDbDataAdapte r, ds As DataSet
Private Sub Form2_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
conn = New OleDbConnection
conn.Connection String = "provider=micro soft.jet.oledb. 4.0; Data
Source = db2test.mdb"
da = New OleDbDataAdapte r
ds = New DataSet
da.SelectComman d = New OleDbCommand
da.SelectComman d.Connection = conn
da.SelectComman d.CommandType = CommandType.Tex t
da.SelectComman d.CommandText = "Select * from Table1"
da.Fill(ds, "tbl1")
dgrv1.DataSourc e = ds.Tables(0)
End Sub

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
da.UpdateComman d = New OleDbCommand
da.UpdateComman d.Connection = conn
da.UpdateComman d.CommandType = CommandType.Tex t
da.UpdateComman d.CommandText = "Update Table1 Set Field3 = 'aaa'
where ID = 3"
conn.Open()
da.UpdateComman d.ExecuteNonQue ry()
'da.Update(ds, "tbl1") '--<<---had to use ExecuteNonQuery since
this
didn't run
ds.Clear()
da.Fill(ds, "tbl1")
dgrv1.DataSourc e = ds.Tables(0)
conn.Close()
MessageBox.Show ("Updated")
End Sub
End Class

the first routine loads data from a table in an Access mdb. The second
routine updates the table. The only thing is that I couldn't get the
da.Update thing to work (like it does with sql server). So I used
da.UpdateComman d.ExecuteNonQue ry which did work. The only thing is that
you
have to open and close the connection yourself where usually the
dataAdapter
takes care of that automatically.

Rich
"Scotty" wrote:
>I get stuck to write an update, insert and delete command, i am looking
for
some help to start

Whats the best way to update 2 tables toe the database (Access)
below my code used to load my data.(2 tables)
Do someone has a good sample code to help me?

Many thanks in advance,
Marc.

'************b egin code*********** ****
Imports System
Imports System.Data
Imports system.Data.ole db

Public Class frmPostcodesTyp edDS

Inherits System.Windows. Forms.Form

Dim strPath As String = "C:\AADatabases \BeActionData.m db"
Dim strCnBeActionDa ta As String = "provider=micro soft.jet.oledb. 4.0;
Data Source=" & strPath

Dim daActionData As OleDbDataAdapte r
'Dim mydtPostcodes As dtPostcodes = New dtPostcodes()
Dim cnBeActionData As New OleDbConnection (strCnBeActionD ata)

Dim dsLandenPostcod es As New DataSet
Dim da1 As New OleDbDataAdapte r
Dim da2 As New OleDbDataAdapte r

Dim dt1 As New DataTable
Dim dt2 As New DataTable
Private Sub frmPostcodes_Lo ad(ByVal sender As System.Object, ByVal e
As
System.EventAr gs) Handles MyBase.Load
Call LoadPostcodes()
End Sub
Sub LoadPostcodes()

' Dim dsLandenPostcod es As New DataSet
Dim dt1 As New DataTable
Dim dt2 As New DataTable
dsLandenPostcod es.Tables.Add(d t1)
dsLandenPostcod es.Tables.Add(d t2)
Dim da1 As New OleDbDataAdapte r("Select * from [tblLanden]",
cnBeActionData )
Dim da2 As New OleDbDataAdapte r("Select * from
[tblLandenPostco des]", cnBeActionData)

da1.FillSchema( dt1, SchemaType.Mapp ed)
da2.FillSchema( dt2, SchemaType.Mapp ed)

Dim rel As New DataRelation("F KPostcLanden_Po stcodes",
dsLandenPostco des.Tables(0).C olumns("Landcod e"),
dsLandenPostco des.Tables(1).C olumns("Landcod e"))
dsLandenPostcod es.Relations.Ad d(rel)

Dim bsPostcodeLande n As New BindingSource
bsPostcodeLande n.DataMember =
dsLandenPostco des.Tables(0).T ableName
bsPostcodeLande n.DataSource = dsLandenPostcod es

Dim bsPostcodes As New BindingSource
bsPostcodes.Dat aSource = bsPostcodeLande n
bsPostcodes.Dat aMember = "FKPostcLanden_ Postcodes"

da1.Fill(dt1)
da2.Fill(dt2)

Me.dgvPostcodeL anden.DataSourc e = bsPostcodeLande n
Me.dgvPostcodes .DataSource = bsPostcodes
End Sub
'************E inde code*********** ****

Oct 5 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2889
by: theWizK | last post by:
Hello all. I have noticed that when I generate a strongly-typed dataset from an xml schema that the DataTables that are generated have their constructors marked as internal. What this means is when I try to instantiate one of the strongly-typed tables from this dataset from a different assembly, I cannot. Let me provide examples... If I have a simple dataset like this:
1
6089
by: Job Lot | last post by:
I am confused how strongly typed dataset is different from un-typed dataset. Is there any good link explaining pros and cons of both? Which one should be used preferably?
2
4375
by: David | last post by:
I have been developing applications with Java for quite a while but I am new to .NET development. I am trying to learn the ".NET way" of creating Strongly Typed Objects from a database. The Enterprise Library seems pretty close to what I am used to in Java but I am not sure how to create strongly-typed DataSets. I see that I can use the LoadDataSet method from a Microsoft.Practices.EnterpriseLibrary.Data.Database but I am not clear on how...
3
6044
by: sck10 | last post by:
Hello, I am creating a form for users to enter information about a lab and the members of the lab. I have one form (FormView) that they use to enter information about that lab. The keyvalue is "LabLocation_ID". With an existing lab, they then need to add the members for that lab. So, what I am trying to do is the following. With the FormView of the Lab open, the user will click a button to open a FormView (InsertMode) and add a new...
1
1086
by: Jim | last post by:
Using VS 2005. I have bound fields on a form bound to a dataset(s) and I want to add various data elements to fields in the DB that are not comming from bound fields. This is what I have resorted to and it's not very efficient. Any suggestions would be greatly appreciated daPtName.InsertCommand.Parameters.Item("@Fname").Value = txtFname.Text daPtName.InsertCommand.Parameters.Item("@Mname").Value = txtMname.Text...
2
1872
by: Scotty | last post by:
I get stuck to write an update, insert and delete command, i am looking for some help to start Whats the best way to update 2 tables toe the database (Access) below my code used to load my data.(2 tables) Do someone has a good sample code to help me? Many thanks in advance, Marc.
5
5361
by: Monty M. | last post by:
Hello; I was wondering if anyone can assist me with this problem. Here are the tools I am using: Language: C# Database: MS SQL Server 2000 Application: Visual Studio 2005 1. I have a table whose primary key is a varchar data type.
6
14153
by: Dhananjay | last post by:
hello everyone i have got a problem i want to design business layer, data access layer , presentation layer for asp.net using C#.net , can anyone help me to solve this problem. i want some resources to complete this. i am trying very hard. Do you have any idea about website or any links where i can find some examples based on this concept.can you plz provide me , its urgent i want this solution with an example, if u have plz provide me. ...
12
4159
by: Simon | last post by:
Hi all, I'm having a baffling problem with a windows service that I'm working on. Basically, I am using a typed dataset to insert a large number of rows into an SQL Server 2005 database. But there's a memory leak that seems to be to do with calling the data adapters update method. It's making the memory usage go through the roof and ultimately the service crashes after running out of memory.
0
9563
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9386
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10144
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9997
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9937
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9822
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8821
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2793
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.