콤보 상자에서 선택한 항목에 따라 텍스트 상자를 채우려고합니다. 문제는로드시 다음 오류가 발생하고 visual studio에서 next..next를 누릅니다. 실제로 수행 할 작업을 수행합니다.콤보 상자가 선택되어서 양식로드시 오류가 발생했습니다. 인덱스
로드시 문제를 어떻게 해결할 수 있습니까? 양식 부하
코드는 콤보 상자의 선택된 인덱스에 대한
private void UpdateProduct_Load(object sender, EventArgs e)
{
DataSet ds = GetAllItems();
comboBox2.DataSource = ds.Tables[0];
comboBox2.DisplayMember = "Product Name";
comboBox2.SelectedIndex = 0;
}
코드입니다 난 단지 문제가
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
// string selectedText = this.comboBox2.GetItemText(this.comboBox2.SelectedItem);
DataSet d = GetProductInfo(comboBox2.Text);
if (d.Tables.Count > 0)
{
textBox2.Text = d.Tables[0].Rows[0]["Quantity"].ToString();
textBox3.Text = d.Tables[0].Rows[0]["Color"].ToString();
textBox4.Text = d.Tables[0].Rows[0]["Size"].ToString();
textBox5.Text = d.Tables[0].Rows[0]["Price"].ToString();
}
}
때 처음으로 양식로드합니다.
GetProductInfo 코드
public DataSet GetProductInfo(string product)
{
DataSet dataSet = new DataSet();
OleDbConnection oleConn = new OleDbConnection(connString);
try
{
oleConn.Open();
string sql = "SELECT [Quantity], [Color], [Size], [Price] FROM [Product] WHERE [Product Name]= '" + product + "'";
OleDbDataAdapter dataAdapter = new OleDbDataAdapter(sql, oleConn);
dataAdapter.Fill(dataSet, "Product");
}
catch (Exception ex)
{
MessageBox.Show("An exception has been occured\n" + ex.ToString());
Console.WriteLine(ex.ToString());
}
finally
{
oleConn.Close();
}
if (dataSet.Tables["Product"].Rows.Count <= 0)
return null;
return dataSet;
}
스택 추적은
System.NullReferenceException occurred
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=Purchase Management
StackTrace:
at Purchase_Management.UpdateProduct.comboBox2_SelectedIndexChanged(Object sender, EventArgs e) in c:\Users\Amrit\Desktop\Purchase Management\Purchase Management\UpdateProduct.cs:line 99
InnerException:
당신은'GetProductInfo()'에 대한 코드를 보여줄 수 있습니까? –
(Visual Studio의 디버그 모드에서) 오류를 다시 복제하고 예외 설명 팝업이 표시되면 "예외 세부 정보를 클립 보드로 복사"링크를 클릭하십시오. 중간 단계 (메모장 등 사용)에서 세부 정보를 위조하여 회사에서 알려주지 못하는 비밀 정보를 아무도 알 수 없으면 해당 세부 정보에서 StackTrace (부분적으로 검열 된 경우) 섹션을 보내주십시오. –