Dear Sirs:
I'm not sure if this is the right forum or not, but I have a C# WinForms application with a ListView control, containing 3-columns, i.e., "Name", "Email", and "Phone".
It also has 4-textboxes on the form, i.e., "FirstName", "LastName", "Email", and "Phone#", for which the user can enter data and save it to the database.
The application has a SQL database with a simple "AddressBook" table with an autoincremented column, i.e., "AddressID" and columns for "FirstName", "LastName", "Email", and "PhoneNumber" fields.
I also have an "AddressBookDataSet" and an "AddressesTableAdapter".
I'm not interested in anything databound, nor in using a DataGridView; but would like to know how to retrieve data from each row/column and use it to populate the ListView's ListItem and SubItem's. I'll also need to concatenate the FirstName and LastName column data for the ListView's "Name" column.
I have searched unsuccessfully for examples, both in the MSDN help file as well as Online but can't find what I need.
I can successfully Insert data into the table but need to know how to use my query "SELECT FirstName, LastName, Email, PhoneNumber FROM dbo.Addresses" to populate those ListView items.
Thank you in advance.
Loading
Richard ArnoldPosted Aug 3, 2009, 4:46 PM
Thanks for responding to my post.
I'm not sure what you mean on the first line by string filer = "profile like '%" + profile + "%'";
What do you mean by "profile"? There is nothing in my code with the name of "profile". And are you trying to set a Filter?
If I write it out line by line, I have the following questions for you.
1) string filer = "profile like '%" + profile + "%'";
2) dtable.DefaultView.RowFilter = filer;
3) dtable.Select(filer);
4) lstForms.Items.Clear();
5) for (int i = 0; i < dtable.DefaultView.Count; i++)
6) {
7) DataRow drow = dtable.Rows[i];
8) if (drow.RowState != DataRowState.Deleted)
9) {
10) ListViewItem lvi = new ListViewItem(drow["FormName"].ToString() );
11) lvi.SubItems.Add(drow["ID"].ToString() );
12) lstForms.Items.Add(lvi);
13) }
14)}
On line 10, do you mean for me to supply the actual name of the WinForms form, i.e., ["FormName"]?
On line 12, I'm assuming you're referring to the name of my ListView control, i.e., lstForms.
Would you please clarify what you mean on line 1 by "profile", and what you mean on line 10 by ["FormName"]?
Thank you though, the rest of the code makes sense to me.
Sincerely
Bhushan SahniPosted Aug 3, 2009, 12:39 AM