Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法使用c#windows应用程序在MS access数据库中插入数据_C#_Ms Access 2010_Oledb_Sql Insert_Insert Into - Fatal编程技术网

无法使用c#windows应用程序在MS access数据库中插入数据

无法使用c#windows应用程序在MS access数据库中插入数据,c#,ms-access-2010,oledb,sql-insert,insert-into,C#,Ms Access 2010,Oledb,Sql Insert,Insert Into,我曾尝试在MS access数据库中插入数据,但数据库中未添加数据,并且未给出错误 private void btnsubmit_Click(object sender, EventArgs e) { int row = dataGridView1.RowCount; for (int i = 0; i < row - 1; i++) { String str = "INSERT INTO JDS_Dat

我曾尝试在MS access数据库中插入数据,但数据库中未添加数据,并且未给出错误

  private void btnsubmit_Click(object sender, EventArgs e)
    {

        int row = dataGridView1.RowCount;
        for (int i = 0; i < row - 1; i++)
        {
            String str = "INSERT INTO JDS_Data(job_no,order_no,Revision,DesignSpec,Engine_Type,Record_date,LE_IN_Designer,CPH_Designer,Exp_Del_Week,Action_code,Rev_Description,Ref_pattern,Name_of_mock_up,EPC_Drawing,Turbocharger_no_Type,Engine_Specific_Requirement,Draft_sketch_with_details,Air_cooler_type,Description_of_Job,SF_No,Standard,Prority_Sequence,Remark,Part_family,Modified_Date,User)  values('" + txtjobno.Text + "','" + txtorderno.Text + "','" + txtrevison.Text + "','" + txtds.Text + "','" + txtenginetype.Text + "','" + dateTimePicker1.Text + "','" + txtleindesigner.Text + "','" + txtcphdesigner.Text + "','" + txtexpweek.Text + "','" + txtactioncode.Text + "','" + txtrevdescription.Text + "','" + txtrefpatern.Text + "','" + txtmockup.Text + "','" + txtepcdwg.Text + "','" + txtturbono.Text + "','" + txtenginereq.Text + "','" + txtdraft.Text + "','" + txtaircolertype.Text + "','" + txtdespjob.Text + "','" + dataGridView1.Rows[i].Cells[0].Value.ToString() + "','" + dataGridView1.Rows[i].Cells[1].Value.ToString() + "','" + dataGridView1.Rows[i].Cells[2].Value.ToString() + "','" + txtremark.Text + "','" + dataGridView1.Rows[i].Cells[3].Value.ToString() + "','" + DateTime.Today + "','" + mdlconnection.user_name + "')";

            int dd = mdlconnection.excuteQuery(str);
            MessageBox.Show(str);
            //if (dd > 0)
            {
                MessageBox.Show("Data Saved Successfully..!!!");

            }

        }

    }   
private void btnsubmit\u单击(对象发送者,事件参数e)
{
int row=dataGridView1.RowCount;
对于(int i=0;i0)
{
MessageBox.Show(“数据保存成功..!!!”;
}
}
}   

您的语法可能不正确。使用字符串串联构造查询总是一个坏主意。使用参数化查询字符串,通过
OdbcCommand.Parameters处理内置参数值。添加(…)
您的查询在第行下方有
语法
错误使用

String str = "INSERT INTO JOB_Quality_Rating(Team,JOB_Type,Designer_Name,AUR_NO,Task_No,Sub_Function_no,Severity_Level,Checkpoints,Points_Deducted,Total_Points,Submitted_By,Submitted_Date) values('" + comboBox1.SelectedItem + "','"+comboBox7.SelectedItem+"','" + comboBox3.SelectedItem + "','" + comboBox6.SelectedItem + "','" + cmbtaskno.SelectedItem + "','" + comboBox2.SelectedItem + "','" + dataGridView1.Rows[i].Cells[0].Value.ToString() + "','" + dataGridView1.Rows[i].Cells[1].Value.ToString() + "','" + dataGridView1.Rows[i].Cells[2].Value.ToString() + "','" + txtTotal.Text + "','" + mdlconnection.user_name + "','" + dateTimePicker1.Text + "')";
而不是

String str = "INSERT INTO JOB_Quality_Rating(Team,JOB_Type,Designer_Name,AUR_NO,Task_No,Sub_Function_no,Severity_Level,Checkpoints,Points_Deducted,Total_Points,Submitted_By,Submitted_Date) values('" + comboBox1.SelectedItem + "',,'"+comboBox7.SelectedItem+"','" + comboBox3.SelectedItem + "','" + comboBox6.SelectedItem + "','" + cmbtaskno.SelectedItem + "','" + comboBox2.SelectedItem + "','" + dataGridView1.Rows[i].Cells[0].Value.ToString() + "','" + dataGridView1.Rows[i].Cells[1].Value.ToString() + "','" + dataGridView1.Rows[i].Cells[2].Value.ToString() + "','" + txtTotal.Text + "','" + mdlconnection.user_name + "','" + dateTimePicker1.Text + "')";

希望有帮助。

cyberj0g是正确的,您的语法不正确。特别是,您的值列表中缺少一个值:
…comboBox1.SelectedItem+“,”+comboBox7.选择EdItem…
。您不能以这种方式传递空值。请在此处传递NULL或从字段列表子句中删除相应字段:
…团队、设计师名称…
(以及额外的逗号或课程)。

您可以尝试以下操作- -尝试在access中手动执行查询字符串(str变量中形成的内容),以确保语法中没有错误,并在那里成功执行 -将执行语句包装在try..catch块中以获取错误详细信息
-确保连接指向正确的数据库实例

能否同时显示
mdlconnection.excuteQuery
?是否调试了代码并查看了发生的情况?是否确定连接字符串是正确的?列类型是什么?顺便问一下,您应该始终使用这种字符串连接。这种类型的字符串连接对您是开放的攻击。