Solved

databindings

Posted on 2006-07-08
3
199 Views
Last Modified: 2010-04-23
hello experts ,
I want to query database and retrieve value of a field of table , and put it in textbox1,I wrote these :


Dim cn As OleDbConnection = New OleDbConnection("provider=microsoft.jet.oledb.4.0; _
data  source=d:\db1.mdb")
cn.Open()
Dim da As OleDbDataAdapter = New OleDbDataAdapter _("select * from table1 where fname='hossein'", cn)
Dim ds As DataSet = New DataSet
TextBox1.DataBindings.Add("text", ds, "table1.lname")
da.Fill(ds)

but when I run this , error appear :

An unhandled exception of type 'System.ArgumentException' occurred in system.windows.forms.dll

Additional information: Cannot create a child list for field table1.

please help me to correct these codes,
is there better way?
thanks
0
Comment
Question by:farhadtolooie
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 34

Expert Comment

by:Sancler
ID: 17064406
Unless you are using more than one DataTable, you don't need a DataSet, you can just work with a DataTable.  If you are using a DataAdapter you do not need explicitly to open the Connection: the DataAdapter opens and closes it automatically.  But if you are going explicitly to .Open a Connection, you should always .Close it, too.  Unless you are using a strongly typed dataset (i.e. one which is defined at design time) you should put your databinding after, not before, you fill your table.  Otherwise, as the error message says, the binding will not be able to find the table/field it is referred to: it won't yet exist.  

Rolling all that together (and assuming that your table has a field called "lname") try this.

Dim cn As OleDbConnection = New OleDbConnection("provider=microsoft.jet.oledb.4.0; _
data  source=d:\db1.mdb")
Dim da As OleDbDataAdapter = New OleDbDataAdapter _("select * from table1 where fname='hossein'", cn)
Dim dt As New DataTable
da.Fill(dt)
TextBox1.DataBindings.Add("text", dt, "lname")

Roger
0
 

Author Comment

by:farhadtolooie
ID: 17064543
hello roger
I wrote your code and run it , but this error occur:

An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll

what doyou think about it?
what's the problem?

farhad
0
 
LVL 34

Accepted Solution

by:
Sancler earned 55 total points
ID: 17064688
I think this is the problem

Dim cn As OleDbConnection = New OleDbConnection("provider=microsoft.jet.oledb.4.0; _
data  source=d:\db1.mdb")

I just copied and pasted it as it stood.  There are TWO spaces, not one, between 'data' and 'source'.  

Here it is corrected, and on one line.  I've just tested it (although with a different data source) and it works OK for me

        Dim cn As OleDbConnection = New OleDbConnection("provider=microsoft.jet.oledb.4.0; data source=c:\test\test.mdb")

Copy and paste that, and substitute your d:\db1.mdb for my c:\test\test.mdb

Roger
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question