Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Problem with TextBox and MS Access
 

Problem with TextBox and MS Access

I am writing a form with serveral textboxes, those textboxes are going to display serveral records with same criteria. How can I show those records on those textboxes ?

Dim ShowPhonestrSelect As String = "select autoid, id, phone, type, phone &typeasshowphone from phone where id = '" & CboFiltered.SelectedValue & "'"

Dim ShowPhoneDA As New OleDb.OleDbDataAdapter(ShowPhonestrSelect, ShowPhoneconn)
Dim ShowPhoneDS As New DataSet

ShowPhoneconn.Open()

ShowPhoneDA.Fill(ShowPhoneDS, "phone")

What should I do then ??

Thank You

Newbie Kam  Friday, January 05, 2007 10:17 AM
Um, no ... a ListView cannot be databound, there is no DataSource property. The others (DataGrid, DataGridView) can be databound.
BonnieB  Sunday, January 07, 2007 4:52 PM
Are you going to show different records at the same time?

If you only show one records at the time and you are using textboxes, and ff you work with .Net 2.0 (Visual Studio 2005), then you need to try out the BindingSource control.

A BindingSource is a easy way to Bind controls to a dataSet.

1) create a bindingsource
2) bind your bindingsource to the data (DataSource and DataMember Property)
3) Bind your controls (textboxes) to the BindingSource
a) programmatically using the DataBindings class  "textbox.databindings.add( ...) "
b) using the designer (recommended for starters)
4) add a binding navigator
5) set the bindingsource property of this BindingNavigator to the bindingsource you created in step 2.

You can do all these steps very easy when you use the "data sources" window.

Hope it helps
Damiaan
DamPee  Friday, January 05, 2007 12:57 PM

yes,I am going to show all records with the same criteria at the same time.

e.g.autoid id phone type

00001 001 12345678 Home

00002 001 87654321 Business

00003 001 78945612 Business (Fax)

and I have 3 set of textboxes,

txtphone1:txtphonetype1, txtphone2:txtphonetype2, txtphone3:txtphonetype3

If I write the code :

Txtphone1.DataBindings.Add("Text", ShowPhoneDS.Tables("phone"), "phone")

txtphonetype1.databindings.add("Text", ShowPhoneDS.Tables("phone"), "type")

What should I do if I want to show the rest of the records in textboxes 2 and 3 ?

Thank You.

Newbie Kam  Saturday, January 06, 2007 2:04 AM

Chris,

Rather than sets of TextBoxes, you'd be better off using a DataGrid, a DataGridView or a ListView.

BonnieB  Sunday, January 07, 2007 1:15 AM
You just need to set the datasource of these (datagrid, datagridview or listview) controls to the bindingsource, and off you go.
DamPee  Sunday, January 07, 2007 4:26 PM
Um, no ... a ListView cannot be databound, there is no DataSource property. The others (DataGrid, DataGridView) can be databound.
BonnieB  Sunday, January 07, 2007 4:52 PM

I'm trying to use DataGridView now,

Thank You

Newbie Kam  Monday, January 08, 2007 1:57 AM
Hey Chris, you gave yourself the "marked as an answer" ... shouldn't it have gone to me?
BonnieB  Friday, January 12, 2007 3:22 PM

You can use google to search for other answers

Custom Search

More Threads

• Don´t passa to next row
• DataGridView set index of Row Selector
• ToolStripMenuItem question
• Data Binding With radio Buttons
• Paint event does not get fired
• C# working with DataBases
• Crash when not using optimistic concurrency
• hierarchical DataGridView or ListView or something similiar
• Formatting textbox for currency. Weird annoying bug ..
• Datagridviewcolumn backcolor