我的场景是从数据库填充组合框,显示客户名称,并使用标识增量保存id的值。填充组合框
当此代码运行时,我收到一个错误Procedure or function 'spSelectCustomerById' expects parameter '@id', which was not supplied
。
SqlConnection conn = new SqlConnection(connectionString);
conn.Open();
//SelectCustomerById(int x);
comboBoxEx1.Items.Clear();
SqlCommand comm = new SqlCommand("spSelectCustomerByID", conn);
//comm.Parameters.Add(new SqlParameter("cust_name", cust_name));
//comm.CommandText = "spSelectCustomerByID";
comm.Parameters.Add(new SqlParameter("cust_id", SqlDbType.Int));
comm.CommandType = CommandType.StoredProcedure;
comm.ExecuteNonQuery();
SqlDataAdapter sdap = new SqlDataAdapter(comm);
DataSet dset = new DataSet();
sdap.Fill(dset, "cust_registrations");
if (dset.Tables["cust_registrations"].Rows.Count > 0)
{
comboBoxEx1.Items.Add("cust_registrations").ToString();
}
comboBoxEx1.DataSource = dset;
comboBoxEx1.DisplayMember = "cust_name";
如何从数据库填充组合框?
那么你的问题是什么? – 2012-07-17 09:16:06
有什么问题? – 2012-07-17 09:16:51
你为什么要做'comm.ExecuteNonQuery();'然后使用dataadapter填充数据集,你不需要'comm.ExecuteNonQuery();' – Habib 2012-07-17 09:20:47