Question Text box databind

spaul

Member
Joined
Jul 2, 2008
Messages
10
Programming Experience
Beginner
I'm a newbie to programming and I'm trying to put together a ADO program in visual studio.net using VB. What I need to do is bind data from the first record in a dataset to a text box. This is the code I have currently:

VB.NET:
Expand Collapse Copy
txtType.DataBindings.Add("Text", objDataSet, "tblMaps.fldtype")

I've also tried this:

VB.NET:
Expand Collapse Copy
txtType.DataBindings.Add(New Binding("Text", objDataSet, "tblMaps.fldtype"))

This is the error I get with both of the above:

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

Additional information: Cannot create a child list for field tblMaps.
Can anybody tell me what I'm doing wrong? Thanks a lot.
 
Hello,

Did you check if you have used the correct spelling for the field name. You
have used the code correctly. There is certainly an issue with the
parameters provided and the actual schema of the database table.

Regards,

Allen
 
Yeah I checked the spelling over.. everything looks like it should work. I tried this with the same results:

VB.NET:
Expand Collapse Copy
        Dim binType As Binding
        binType = New Binding("Text", objDataSet, "tblMaps.fldtype")
        txtType.DataBindings.Add(binType)

Any other ideas? Thanks.
 
OK I changed the second line of code to:

VB.NET:
Expand Collapse Copy
binType = New Binding("Text", objDataSet, "fldType")

Now I get the error:

Additional information: Cannot bind to property or column fldType on DataSource.
 
I'm a newbie to programming and I'm trying to put together a ADO program in visual studio.net using VB. What I need to do is bind data from the first record in a dataset to a text box.
DataSets dont have data. DataTables do.

Youre using .NET 3.5. Why are you writing the binding code yourself? All you do is click on the text box in the form, expand (Data Bindings) property, and add one to the .Text property. Pick the relevant table and column. if the dataset is already a member of the form, choose FormX List Instances rather than Project Data Sources - this will make sense when you do it.

Lastly, the easiest way to get a bound textbox is to: have a dataset, show the Data Sources window, drag the column out of the window, onto the form
 
When I go to the databinding property of the textbox there are no available datasources, but I do have a dataset loaded into the program. I can see the query results in the dataset displayed in a datagrid on the form. Why does this dataset not show in the textbox databinding .text property dropdown?

Also, where do I find the Data Sources window?

Thanks again for responding cjard
 
er.. I normaqlly find them on the View menu..

View.. Data Sources


That said, I use 2005, so 2003 may operate differently in this regard. I hope someone with 2003 will be along to help out. You can also consider upgrading your very old IDE :)
 
Back
Top