473,503 Members | 1,654 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with DataAdapter Fill and Binding

I need help in understanding the DataAdapter Fill method and how it
relates to the binding to controls on a form. I have a table called
tbl_CID_XRef on SQL Server. I have written as a test the simple code
below:

----------------------------------------------------------------

Private cob As SqlCommandBuilder
Private con As SqlConnection
Private cur As CurrencyManager
Private dap As SqlDataAdapter
Private dst As New DataSet

Try
con = New SqlConnection("workstation id=KC...")
dap = New SqlDataAdapter("SELECT CLIENT_ID, CLIENT FROM
tbl_CID_Xref", con)
cob = New SqlCommandBuilder(dap)
dap.Fill(dst, "tbl_CID_XRef")
'
' Bind the controls
'
txtClientID.DataBindings.Add("Text", dst, "CLIENT_ID")
txtClient.DataBindings.Add("Text", dst, "CLIENT")
cur = Me.BindingContext(dst, "tbl_CID_XRef")

Catch ex As Exception
MessageBox.Show("Error: " & ex.Message)
End Try

----------------------------------------------------------------

This code works just fine. Now if I take out the "tbl_CID_XRef" from
the Fill method, shown below, I get the error: "Cannot create a child
list for field tbl_CID_XRef."

dap.Fill(dst)

I have a vague understanding why. But the reason why I will want to do
this is when my SELECT statement is on a JOIN of two tables like the
following:

SELECT tbl_CID_XRef.CLIENT_ID,
tbl_CID_XRef.CLIENT,
tbl_CID_XREF_History.PlanType
FROM tbl_CID_XREF_History
INNER JOIN tbl_CID_XRef ON tbl_CID_XREF_History.CLIENT_ID =
tbl_CID_XRef.CLIENT_ID

I'm joining two tables (tbl_CID_XRef and tbl_CID_XRef_History).

How do I write the Fill method for something like this?

Nov 21 '05 #1
2 2093
Hi,

<pw****@gmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
I need help in understanding the DataAdapter Fill method and how it
relates to the binding to controls on a form. I have a table called
tbl_CID_XRef on SQL Server. I have written as a test the simple code
below:

----------------------------------------------------------------

Private cob As SqlCommandBuilder
Private con As SqlConnection
Private cur As CurrencyManager
Private dap As SqlDataAdapter
Private dst As New DataSet

Try
con = New SqlConnection("workstation id=KC...")
dap = New SqlDataAdapter("SELECT CLIENT_ID, CLIENT FROM
tbl_CID_Xref", con)
cob = New SqlCommandBuilder(dap)
dap.Fill(dst, "tbl_CID_XRef")
'
' Bind the controls
'
txtClientID.DataBindings.Add("Text", dst, "CLIENT_ID")
txtClient.DataBindings.Add("Text", dst, "CLIENT")
cur = Me.BindingContext(dst, "tbl_CID_XRef")

Catch ex As Exception
MessageBox.Show("Error: " & ex.Message)
End Try

----------------------------------------------------------------

This code works just fine. Now if I take out the "tbl_CID_XRef" from
the Fill method, shown below, I get the error: "Cannot create a child
list for field tbl_CID_XRef."

dap.Fill(dst)

I have a vague understanding why. But the reason why I will want to do
this is when my SELECT statement is on a JOIN of two tables like the
following:

SELECT tbl_CID_XRef.CLIENT_ID,
tbl_CID_XRef.CLIENT,
tbl_CID_XREF_History.PlanType
FROM tbl_CID_XREF_History
INNER JOIN tbl_CID_XRef ON tbl_CID_XREF_History.CLIENT_ID =
tbl_CID_XRef.CLIENT_ID

I'm joining two tables (tbl_CID_XRef and tbl_CID_XRef_History).

How do I write the Fill method for something like this?


A DataSet contains DataTable's.

The name you use as the second parameter, is the name that will be used for
the DataTable that will be created or updated in the DataSet ( dst ). When
you bind you have to use the same TableName:
dap.Fill( dst, "abc" )
txtClientID.DataBindings.Add("Text", dst, "abc.CLIENT_ID")

Now, if you don't specify a TableName then the default is "Table", so you
need to bind to "Table":
dap.Fill( dst )
txtClientID.DataBindings.Add("Text", dst, "Table.CLIENT_ID")

It doesn't matter if you do a Join query or not, the name applies to the
created DataTable which is also the name you will have to use when you bind.
It doesn't need to relate to the table name(s) in the database.
HTH,
Greetings


Nov 21 '05 #2
Thanks Bart! That's the information I needed.

Nov 21 '05 #3

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

Similar topics

2
2864
by: Joe Fetters via .NET 247 | last post by:
Have googled and read the VS.NET documentation can't seem to getthe answer to the following. Environment: Framework 1.1 VB.NET WinForm Access database Using all automagic tools (DataAdapter...
5
4537
by: JJ | last post by:
Hi, I created a DataAdapter, connection object and dataset generated from DataAdapter by dragging DataAdapter compenent to win form. Now in the code behind I want to use that DataAdapter. I go...
1
1048
by: John McClamrock | last post by:
Hello, I'm just starting out with ASP.NET and it looks great. I have minimal programming experience and have some PHP experience. I've also pretty much mastered HTML. I need a little help here....
2
3457
by: Jeff Thur | last post by:
I am trying to Execute a simple Stored Procedure using ASP/VB. I have spent numerous hours with this, researching books and looking on the internet. I can't get a direct answer. THis is my...
1
963
by: Agnes | last post by:
in my dataadapter's command text, I only select the current month records and then use binding manager to bind it. The user can press'button' to move forward or backward to that record. I need to...
13
2062
by: Doug Bell | last post by:
Hi, I thought I had this sorted this morning but it is still a problem. My application has a DataAccess Class. When it starts, it: Connects to a DB (OLE DB) If it connects it uses an...
12
7933
by: chreo | last post by:
I GIVE UP...I can't refresh datagrid (dataset) I have datagrid = dgrPaczki Datasource of that datagrid = DataSetPaczki1.PACZKI_PAKOWALNIA (forgive me Polish words) Dataadapter which fills my...
4
4602
by: jon f kaminsky | last post by:
Hi- I've seen this problem discussed a jillion times but I cannot seem to implement any advice that makes it work. I am porting a large project from VB6 to .NET. The issue is using the combo box...
8
2672
by: Zorpiedoman | last post by:
I keep getting a concurrency exception the second time I make a change and attempt to update a dataadapter. It appears this is by design, so there must be something I can do to avoid it. ...
0
7072
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...
0
7271
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,...
0
7319
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...
0
5570
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,...
0
4666
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...
0
3149
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1498
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 ...
1
730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
373
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...

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.