Bob Goblin
Bob Goblin

Reputation: 1269

Bind Query Results To Combo Box

This is what I have, and it is not producing any errors, but the combo box is not displaying the results of my SQL statement either?

This doesn't produce any error, but my combo box gets populated with System.Data.DataRowView

SqlDataAdapter adapter = new SqlDataAdapter();
DataSet ds = new DataSet();
string sql = null;
string connectionString = "";
SqlConnection connection = new SqlConnection(connectionString);
sql = "";
SqlDataAdapter da = new SqlDataAdapter(sql, connectionString);
DataTable 1234 = new DataTable();
da.Fill(1234);
combobox1.DisplayMember = "FirstName";
combobox1.ValueMember = "FirstName";
combobox1.DataSource = ds.Tables[0];
connection.Close();

Upvotes: 0

Views: 957

Answers (1)

Mike Burdick
Mike Burdick

Reputation: 838

DataSet ds never gets added to. Your SqlDataAdapter fills DataTable 1234. Change your code to do this:

combobox1.DataSource = 1234;

Or have you SqlDataAdapter File ds.

Upvotes: 1

Related Questions