[2005] Read From A Dataset Instead Of DataReader
Dear Folks,
i created this thread because i got no help on something setting me back that i presented in another thread. In that thread, someone suggested that i use a dataset instead of a Datareader.
I am trying to populate a form using a DataReader....how can i populate my form by simply using a dataset.
You will excuse me, i know how to create one,fill it and use it but i dont know how to populate each control on my form with a corresponding field of the record accessed by the dataset.
Any Idea will be highly appreciated.
Re: [2005] Read From A Dataset Instead Of DataReader
Add a BindingSource to your form in the designer. The following steps can be done in the designer or in code.
Bind your DataTable to the BindingSource using its DataSource and, optionally, DataMember properties. The BindingSource now acts a way to view the data in the table.
Bind your controls to the BindingSource using their DataBindings property, e.g.
VB Code:
myTextBox.DataBindings.Add("Text", myBindingSource, "ColumnName")
You can now set the Position property of the BindingSource to a record index and every bound control will update. You can then get a DataRowView object for the current record through the Current property.
Re: [2005] Read From A Dataset Instead Of DataReader
Thanks JMC...i wish databindings were better for me!! Alas...i have never liked using them aand i dont use them at all. Is there any other way?
Re: [2005] Read From A Dataset Instead Of DataReader
I am taking a chatter to a remote location i will be back online in an 1 and 1/2 hrs time.
Re: [2005] Read From A Dataset Instead Of DataReader
Quote:
Originally Posted by skea
Thanks JMC...i wish databindings were better for me!! Alas...i have never liked using them aand i dont use them at all. Is there any other way?
Of course: do it all manually. It's up to you, but you're asking how to populate your controls so that implies you wanted some of the work done for you. If that's not the case then just set the appropriate properties as you normally would. Data binding IS the automatic way. If you don't like using them then don't. Plain and simple.
Re: [2005] Read From A Dataset Instead Of DataReader
Quote:
Originally Posted by skea
Dear Folks,
i created this thread because i got no help on something setting me back that i presented in another thread. In that thread, someone suggested that i use a dataset instead of a Datareader.
I am trying to populate a form using a DataReader....how can i populate my form by simply using a dataset.
You will excuse me, i know how to create one,fill it and use it but i dont know how to populate each control on my form with a corresponding field of the record accessed by the dataset.
Any Idea will be highly appreciated.
Dont know if this helps but you could do it a bit more manually like this , but it still uses the DataSet.
VB Code:
For intX = 0 To (intRecordCount - 1)
intAccountID = dsCustomers.Tables(0).Rows(intX).Item("pkAccountID")
strFamilyName = dsCustomers.Tables(0).Rows(intX).Item("fldFamilyName")
strFirstName = dsCustomers.Tables(0).Rows(intX).Item("fldFirstName")
strPCode = dsCustomers.Tables(0).Rows(intX).Item("fldPCode")
Next
Re: [2005] Read From A Dataset Instead Of DataReader
Thanks mikeLynch. i never knew it was that simple.
JMC...thanks too.