我试图通过文本框从用户那里获取输入,并根据插入的数据点击按钮从数据库中查找更多数据然后将所有数据放入数据网格视图,但是当我单击按钮时我的应用程序挂起。 Plz帮助!
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
if(e.ColumnIndex==0)
{
string newvalue;
newvalue = Search_Product.Text.ToString();
con.Open();
SqlDataAdapter da = new SqlDataAdapter("SELECT Product_Code,Rate,SalePrice,CGST,SGST FROM Product_Master where Product_Name='"+newvalue+"'",con);
DataTable dt = new DataTable();
da.Fill(dt);
float CGST = (float.Parse(dt.Rows[0][1].ToString()) * float.Parse(dt.Rows[0][3].ToString())) / 100;
float SGST = (float.Parse(dt.Rows[0][1].ToString()) * float.Parse(dt.Rows[0][4].ToString())) / 100;
dataGridView1.Rows[e.RowIndex].Cells[1].Value = dt.Rows[0][0].ToString();
dataGridView1.Rows[e.RowIndex].Cells[3].Value = dt.Rows[0][2].ToString();
dataGridView1.Rows[e.RowIndex].Cells[4].Value = CGST;
dataGridView1.Rows[e.RowIndex].Cells[5].Value = SGST;
con.Close();
}
//column multiplication
foreach(DataGridViewRow row in dataGridView1.Rows)
{
row.Cells[dataGridView1.Columns[6].Index].Value = (Convert.ToDouble(row.Cells[dataGridView1.Columns[2].Index].Value) * Convert.ToDouble(row.Cells[dataGridView1.Columns[3].Index].Value));
}
}
private void button1_Click(object sender, EventArgs e)
{
DataGridViewCellEventArgs ke = e as DataGridViewCellEventArgs;
dataGridView1_CellEndEdit(sender, ke);
}