为什么我收到错误消息“输入字符串的格式不正确”

时间:2019-02-11 16:04:25

标签: c# datagridview

我正在将数据从datagridview插入数据库中,调试我的代码,发现错误输入字符串的格式不正确。在下面的行

Convert.ToInt32(dgvResult.Rows [i] .Cells [9] .Value.ToString())

此列整数列,当我用整数值替换此行(例如3号)时,插入完成而没有错误,其他整数列也以相同的方式插入而没有任何错误 这是我的代码:

    if (checkApproveResult.Checked == false && chkupdateApproved.Checked == false)
                {
                    for (int i = 0; i < dgvResult.Rows.Count; i++)
                    {
                        result.UPDATE_LAB_RESULTS(Convert.ToInt32(txtOrder.Text),
                                                  dgvResult.Rows[i].Cells[7].Value.ToString(),
                                                  5,
                                                  dgvResult.Rows[i].Cells[6].Value.ToString(),
                                                  txtExamUser.Text,
                                                  DateTime.Parse(DateTimeExamined.Value.ToString()),
                                                  Convert.ToInt32(dgvResult.Rows[i].Cells[2].Value),
                                                  dgvResult.Rows[i].Cells[4].Value.ToString(),
                                                  dgvResult.Rows[i].Cells[5].Value.ToString(),
                                                  Convert.ToInt32(dgvResult.Rows[i].Cells[9].Value.ToString()),
                                                  Convert.ToInt32(txtPno.Text),
                                                  Convert.ToInt32(txtcustid.Text),
                                                  txtReqForm.Text,
                                                  dgvResult.Rows[i].Cells[1].Value.ToString(),
                                                  Convert.ToInt32(dgvResult.Rows[i].Cells[8].Value.ToString()));
                    }
                    MessageBox.Show("Result Saved Successfully ", "Entering Result", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }

   else if (chkupdateApproved.Checked == true)
                {
                    for (int i = 0; i < dgvResult.Rows.Count; i++)
                    {
                        result.ADD_LAB_RESULTS_UPDATES(Convert.ToInt32(txtsampleid.Text),
                            Convert.ToInt32(txtOrder.Text),
                            Convert.ToInt32(dgvResult.Rows[i].Cells[2].Value),
                            Convert.ToInt32(txtgroupid.Text),
                            "YES",
                            6,
                            dgvResult.Rows[i].Cells[11].Value.ToString(),
                            DateTime.Parse(DateTimeExamined.Value.ToString()),
                            dgvResult.Rows[i].Cells[13].Value.ToString(),
                            DateTime.Parse(dateTimeApprove.Value.ToString()),
                            dgvResult.Rows[i].Cells[4].Value.ToString(),
                            dgvResult.Rows[i].Cells[5].Value.ToString(),
                            dgvResult.Rows[i].Cells[6].Value.ToString(),
                            Convert.ToInt32(txtpackageid.Text),
                            Convert.ToInt32(dgvResult.Rows[i].Cells[9].Value.ToString()),
                            2,
                            Convert.ToInt32(txtPno.Text),
                            Convert.ToInt32(txtcustid.Text), txtReqForm.Text, 
                            Convert.ToInt32(dgvResult.Rows[i].Cells[8].Value.ToString()),
                            txtupdatedby.Text,
                            DateTime.Parse(dateupdate.Value.ToString()));

                        }
                    update.UPDATE_LAB_RESULT_STATUS(Convert.ToInt32(txtOrder.Text), Convert.ToInt32(txtsampleid.Text), 2);
                    MessageBox.Show("Result Updated Successfully ", "Update Result", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }

ADD_LAB_RESULT_UPDATES的代码为:

public void ADD_LAB_RESULTS_UPDATES(int SAMPLE_ID, int ORDER_ID,int TESTID,int GROUPID, string NORMAL_RESULT, 
            int SAMPLE_STATUS,string EXAMINED_BY,DateTime EXAMINED_DATE, string APPROVED_BY, DateTime APPROVED_DATE,
            string RESULT_NUMBER, string RESULT_REPORT, string RESULT_NOTE,int packageid, int machine_id, int deptid, 
            int patient_no, int custid, string REQ_FORM_NO,int serial,string UPDATED_BY,DateTime UPDATED_DATE)
        {
            DAL.DataAccessLayer DAL = new DAL.DataAccessLayer();
            DAL.open();
            SqlParameter[] param = new SqlParameter[22];
            param[0] = new SqlParameter("@SAMPLE_ID", SqlDbType.Int);
            param[0].Value = SAMPLE_ID;

            param[1] = new SqlParameter("@ORDER_ID", SqlDbType.Int);
            param[1].Value = ORDER_ID;

            param[2] = new SqlParameter("@TESTID", SqlDbType.Int);
            param[2].Value = TESTID;

            param[3] = new SqlParameter("@GROUPID", SqlDbType.Int);
            param[3].Value = GROUPID;

            param[4] = new SqlParameter("@NORMAL_RESULT", SqlDbType.VarChar, 10);
            param[4].Value = NORMAL_RESULT;

            param[5] = new SqlParameter("@SAMPLE_STATUS", SqlDbType.Int);
            param[5].Value = SAMPLE_STATUS;

            param[6] = new SqlParameter("@EXAMINED_BY", SqlDbType.VarChar, 50);
            param[6].Value = EXAMINED_BY;

            param[7] = new SqlParameter("@EXAMINED_DATE", SqlDbType.DateTime);
            param[7].Value = EXAMINED_DATE;

            param[8] = new SqlParameter("@APPROVED_BY", SqlDbType.VarChar, 50);
            param[8].Value = APPROVED_BY;

            param[9] = new SqlParameter("@APPROVED_DATE", SqlDbType.DateTime);
            param[9].Value = APPROVED_DATE;

            param[10] = new SqlParameter("@RESULT_NUMBER", SqlDbType.VarChar, 50);
            param[10].Value = RESULT_NUMBER;

            param[11] = new SqlParameter("@RESULT_REPORT", SqlDbType.VarChar, 2000);
            param[11].Value = RESULT_REPORT;

            param[12] = new SqlParameter("@RESULT_NOTE", SqlDbType.VarChar, 200);
            param[12].Value = RESULT_NOTE;

            param[13] = new SqlParameter("@packageid", SqlDbType.Int);
            param[13].Value = packageid;

            param[14] = new SqlParameter("@machine_id", SqlDbType.Int);
            param[14].Value = machine_id;

            param[15] = new SqlParameter("@deptid", SqlDbType.Int);
            param[15].Value = deptid;

            param[16] = new SqlParameter("@patient_no", SqlDbType.Int);
            param[16].Value = patient_no;

            param[17] = new SqlParameter("@custid", SqlDbType.Int);
            param[17].Value = custid;

            param[18] = new SqlParameter("@REQ_FORM_NO", SqlDbType.VarChar, 50);
            param[18].Value = REQ_FORM_NO;

            param[19] = new SqlParameter("@serial", SqlDbType.Int);
            param[19].Value = serial;

            param[20] = new SqlParameter("@UPDATED_BY", SqlDbType.VarChar, 50);
            param[20].Value = UPDATED_BY;

            param[21] = new SqlParameter("@UPDATED_DATE", SqlDbType.DateTime);
            param[21].Value = UPDATED_DATE;

            DAL.ExecuteCommand("ADD_LAB_RESULTS_UPDATES", param);
            DAL.close();

        }

参数14 machine_id的错误 还有数据库machine_id int中的表。

有什么错误?

更多信息我首先拥有if语句(更新语句) result.UPDATE_LAB_RESULTS包含相同的参数machine_id,其工作和插入均无错误。 第二条if语句(插入语句),并使用machine_id参数显示错误。

1 个答案:

答案 0 :(得分:1)

您必须检查以下内容:

1-检查参数列表变量类型(字符串,整数,...),并将其与您的过程进行比较,您将在存储过程整数和参数列表字符串中找到一种不同的变量类型。