Quantcast
Channel: Learn C# » Data Binding
Viewing all articles
Browse latest Browse all 2

How to bind Combobox to a table field?

0
0

Binding ComboBox to a table using Stored Procedure

SqlDataAdapter da = new SqlDataAdapter(“StoredProcedureName”,Connection);
da.SelectCommand.CommandType = CommandType.StoredProcedure;
da.SelectCommand.Parameters.Add(new SqlParameter(“@Param1″, Value for @Param1));
DataSet ds = new DataSet( );
da.Fill(ds, “TableName”);
dataGridView1.DataSource = ds;
dataGridView1.DataMember = “TableName”;

Binding ComboBox to a table using Command

Connection.Open();

SqlDataAdapter da = new SqlDataAdapter(“select Uname from Table1″, Connection);

DataSet ds = new DataSet( );

da.Fill(ds, “Table1″);
comboBox1.DataSource =ds.Tables[0];
comboBox1.DisplayMember = “Uname”;

Connection1.Close();

Udhaya

PiSquare Soft Solns



Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images