コンボボックスをデータソース、ディスプレイメンバー、バリューメンバーにバインドしています。私のコンピュータでは正常に動作していますが、クライアント PC では動作していません。以下は私のソースコードです:
cbxAlloyBinding メソッドは、UserControl のコンストラクターから呼び出されます。
private void cbxAlloyBinding()
{
DataTable dt = new DataTable();
SqlDataAdapter adp = new SqlDataAdapter("SELECT alloyName,alloyId FROM alloy", con);
adp.Fill(dt);
if (dt.Rows.Count > 0)
{
cbxMetal.DisplayMember = "alloyName";
cbxMetal.ValueMember = "alloyId";
cbxMetal.DataSource = dt;
}
else
{
cbxMetal.Text = "";
}
}
private void cbxMetal_SelectedIndexChanged(object sender, EventArgs e)
{
if (cbxMetal.SelectedIndex != -1)
{
DataTable dt = new DataTable();
tempcmd = new SqlCommand("SELECT specification,alloyCode FROM alloy where alloyId='" + cbxMetal.SelectedValue + "'", con);
SqlDataAdapter adp = new SqlDataAdapter(tempcmd);
adp.Fill(dt);
if (dt.Rows.Count > 0)
{
txtSpecification.Text = dt.Rows[0]["alloyCode"].ToString();
txtSupplyConditions.Text = dt.Rows[0]["specification"].ToString();
cbxheatBinding();
}
else
{
txtSpecification.Text = "";
}
}
}
これは過去 2 日間から私を悩ませており、ほぼすべてのトリックを試しましたが、まだ機能していません。
クライアントの PC は、Windows 7 Ultimate、SQL Server 2005、および .net Framework 3.5 を使用しています。