Click here to Skip to main content
15,880,608 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
my solution is a c# Windows Application and the DataBase is MySql.
I need to display in every TextBoxes on the form the results of the "Select" statement but, how I have write the code, the TextBoxes on the form are populated only by the first record that the query return to me.
I would like to explain brutally:every TextBox on the form must be like a line of record filled...I hope that my English is clear...

[Moved here by Editor]
I have 2 TextBoxes in main form, the TextBox1 it's used for data entry by barcode reader.
On Validating event of the textbox1, goes run a database query that fill TextXoxes2,and so again for textbox3/4 ..textbox10/11.
At the end of insert, I save all and I close the application.
Now, my big problem, I would to load, at load event of application, the previous data that I have saved before.
I accept any suggest...

Thank's a lot
Posted
Updated 2-Mar-12 1:39am
v2
Comments
walterhevedeich 2-Mar-12 3:02am    
You might want to post your code.
Shahin Khorshidnia 2-Mar-12 7:55am    
Read my improved answer again.
and don't comment in solution part please.

"Don't" is the simple answer.
You could do it, but it would be a manual process, and there would be problems if there are either too many records for the number of textboxes, or too few.
You would be much, much better off not using a DataGridView which would display the data in a table format, more applicable to the row and column nature of the original data. It's also a lot easier!
 
Share this answer
 
Hello,

Good question!
How can a TextBox show a collection of fields?!
TextBox can only show one field if it binds to a collection.

But you could plan for another property like "SelectedField" that is not a collection and bind the TextBoxes to it.



================================

And:
If you want to load the previous data that you have saved. Then Create a table in database (for Example: DataLog):


ID
User_ID
SavedDateTime

This table must relate to the main data table (1 to 1) ID to ID

If you have only one User then Ignore User_ID

Ok you can query for the last Data that the user has entered. on OnLoad or every time.

C#
var data = MyDataCollection.OrderByDescending(d=>(d.DataLog.SavedDateTime && d.DataLog.User_ID == myID));
if(data.Count()>0)
 var selectedData = data.First();
 
Share this answer
 
v7
Tank's for replies,
I would to explain better my necessity.
I have 2 textboxes in main form , the TextBox1 it's used for data entry by barcode reader.
On Validating event of the textbox1, goes run a database query that fill textboxes2,and so again for textbox3/4 ..textbox10/11.
At the end of insert, I save all and I close the app.
Now, my big problem , I would to load, at load event of application, the previous data that I have saved before.
I accept any suggest...Thank's

--------------------------------------------------
I appreciate your reply, but you're in more elevate level than me in C#....

I don't understand your snippet...may you insert more code lines regarding the TextBox that there be filled?

In VS2010 I don't see any SelectedField properties on TextBox...

Thank's again...
 
Share this answer
 
v2
Comments
Shahin Khorshidnia 5-Mar-12 7:07am    
LoL!
Man! you write your question instead of a solution and mark it as accepted?!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900