Hi all. This is my first post… be gentle :)
I'm not looking for the code to make it work... if you could just point me in the right direction... I am self-taught and really need to learn by doing rather then having it given to me. Thanks all!
I have a WinForm with a single ListBox and several TextBoxes. I have an SQL database in the project. I am currently using a connection string to open and read the data filling a dataTable. I have set my ListBox Source and DisplayMember which are working properly. My ListBox displays LastName, FirstName as it should by combining the LastName and FirstName fields in the commandString.
My issue is how I achieve dataBinding/concurrency without using “drop and drag” binding within Visual Studio?
I have to cycle through the records in the ListBox and have the corresponding TextBoxes display the record information. I understand using the SelectedIndexCh anged event for the listbox but I’m missing the “piece” to make the whole thing work.
Here is the code to open, read and fill listbox:
Any help would be appreciated!
I'm not looking for the code to make it work... if you could just point me in the right direction... I am self-taught and really need to learn by doing rather then having it given to me. Thanks all!
I have a WinForm with a single ListBox and several TextBoxes. I have an SQL database in the project. I am currently using a connection string to open and read the data filling a dataTable. I have set my ListBox Source and DisplayMember which are working properly. My ListBox displays LastName, FirstName as it should by combining the LastName and FirstName fields in the commandString.
My issue is how I achieve dataBinding/concurrency without using “drop and drag” binding within Visual Studio?
I have to cycle through the records in the ListBox and have the corresponding TextBoxes display the record information. I understand using the SelectedIndexCh anged event for the listbox but I’m missing the “piece” to make the whole thing work.
Here is the code to open, read and fill listbox:
Code:
string connectionString = "Data Source=walsh\\sqlexpress;Database=PPDOne_db;Integrated Security=True;";
SqlConnection conn = new SqlConnection(connectionString);
string commandString = "SELECT *, NameLast +', ' + NameFirst AS NameFull FROM tblAdvocates ORDER BY NameLast";
SqlDataAdapter dataAdapter = new
SqlDataAdapter(commandString, conn);
DataSet ds = new DataSet();
dataAdapter.Fill(ds, "prog");
dataTable = ds.Tables["prog"];
lbxAdvocates.DataSource = ds.Tables["prog"].DefaultView;
lbxAdvocates.DisplayMember = "NameFull";
lbxAdvocates.SetSelected(0, true);
conn.Close();
Comment