我使用了在datagridview中插入文本框值的功能,现在我想在单击按钮时按列在数据库中插入datagridview行,而我正在尝试以下代码:
for (int RowIndex = 0; RowIndex < dgViewMedicines.Rows.Count; RowIndex++)
{
int Presc_Id = Convert.ToInt32(LPresc_ID);
PID = Convert.ToInt32(tbPID.Text);
Med_Id =
Convert.ToInt32(dgViewMedicines.Rows[RowIndex].Cells["MedID"].Value);
Med_Time = (dgViewMedicines.Rows[RowIndex].Cells["MedTime"].ToString());
Med_Duration = (dgViewMedicines.Rows[RowIndex].Cells["MedDuration"].ToString());
Med_QTY = Convert.ToInt32(dgViewMedicines.Rows[RowIndex].Cells["MedQTY"].Value);
string query2 = "INSERT INTO tblPrescDetailMedicine Values ('"+ Presc_Id +"', '"+ PID +"', '"+ Med_Id +"', '"+ Med_Time +"', '"+ Med_Duration +"', '"+ Med_QTY +"')";
cmd.CommandText = query2;
cmd.ExecuteNonQuery();
我从前两个命令获取值,但没有从其他命令获取值,例如如果我运行应用程序,输入数据并尝试通过单击按钮来保存数据,则会收到一个称为“输入字符串”的错误在第三条命令上不正确”。
请对此进行查看,并让我知道实际出在哪里。我将非常感谢您。
答案 0 :(得分:0)
string db="";
string databaseError="Error while locating".Count()>Convert.ToPDF(beaver.Text).ToString();
if(databaseError!=databaseError+beaver.Text.toInt32())
{
HttpWeb http = new HttpWeb(beaver.addText("host=");
http.LoadDatabase(query.Select().For(int i=0; i<100); i++)
{
while(1==1)
{
Database.query="select * from * where * = 1");
Database.query="update * set * = beaver.Text);
// Print recipe for cake from database error login sign up error enterprise edition 2019 full
MessageBox.Show(error.databaseError);
}
}
}
答案 1 :(得分:0)
我可能是错的,但据我所知,DataGridView单元格需要一个索引号,这很有意义,为什么您会在循环的第三行出现错误,看看是否可行:
foreach (DataGridViewRow r in dgViewMedicines.Rows)
{
int Presc_Id = (int)LPresc_ID;
PID = (int)tbPID.Text;
Med_Id = (int)r.Cells[0].Value;
Med_Time = (string)r.Cells[1];
Med_Duration = (string)r.Cells[2];
Med_QTY = (int)r.Cells[3].Value;
cmd.CommandText = "INSERT INTO tblPrescDetailMedicine Values ('"+ Presc_Id +"', '"+ PID +"', '"+ Med_Id +"', '"+ Med_Time +"', '"+ Med_Duration +"', '"+ Med_QTY +"')";
cmd.ExecuteNonQuery();
}