Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/24.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
使用vb.net插入到选择中无法插入_Vb.net_Ms Access_Select_Insert - Fatal编程技术网

使用vb.net插入到选择中无法插入

使用vb.net插入到选择中无法插入,vb.net,ms-access,select,insert,Vb.net,Ms Access,Select,Insert,我不明白你为什么使用SELECT?我想你应该这样做: 在dbID、companyname、companyaddress、companycontact、contactperson、contactnumber、UserLogin、mDate值@ID、@companyname、@companyaddress、@companycontact、@contactperson、@contactnumber、@UserLogin、@mDate中插入,您必须传递日期值: 调用ExecuteOnQuery方法时是否

我不明白你为什么使用SELECT?我想你应该这样做:

在dbID、companyname、companyaddress、companycontact、contactperson、contactnumber、UserLogin、mDate值@ID、@companyname、@companyaddress、@companycontact、@contactperson、@contactnumber、@UserLogin、@mDate中插入,您必须传递日期值:


调用ExecuteOnQuery方法时是否出现任何错误? 我检查了您的代码,有两条评论: 1您在代码中调用ExecuteOnQuery两次: +------------+ “第一个电话 .ExecuteOnQuery 以 “第二个电话 如果Cmd.ExecuteNonQuery,则 +------------+ 你是故意调用这个方法两次吗? 2.在调用Cmd.ExecuteNonQuery方法之前,请确保连接已打开

如果您仍然面临问题,我在这里发现了一个相关问题,并提供了一些有价值的信息:


我希望这有帮助

欢迎来到SO!到目前为止你试过什么?为了帮助我们帮助您,请添加一个请添加一些上下文来解释代码。是否有任何错误?我将研究如何使用.Parameters。Add@param,SqlDbType.Value=并显式设置每个SqlDataType。我得到了一个解决方案。感谢您的帮助,用于复制目的,这就是为什么我尝试使用insert into select来避免双入口。要避免这种情况,请尝试将insert into替换为insert into。如果主键存在,MySQL将首先删除这一行,然后进行正常的插入。它显示无效的SQL语句OK,我想,您正在使用MySQL。对于MSSQL,使用主键@id在INSERT前面添加DELETE,我认为是这样的:DELETE FROM db,其中id=@id;使用ms access 2010在dbID、companyname、companyaddress、companycontact、contactperson、contactnumber、UserLogin、mDate值@ID、@companyname、@companyaddress、@companycontact、@contactperson、@contactnumber、@UserLogin、@mDateim中插入
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Con.Open()
    Dim Str As String = "INSERT INTO db (ID,companyname,companyaddress,companycontact,contactperson,contactnumber,UserLogin,mDate) SELECT @ID,@companyname,@companyaddress,@companycontact,@contactperson,@contactnumber,@UserLogin,@mDate FROM db WHERE Userlogin = @Userlogin"

    Dim Cmd As New OleDbCommand
    With Cmd

        .CommandText = Str

        .Parameters.AddWithValue("@ID", f1.Text)
        .Parameters.AddWithValue("@companyname", f2.Text)
        .Parameters.AddWithValue("@companyaddress", f3.Text)
        .Parameters.AddWithValue("@companycontact", f4.Text)
        .Parameters.AddWithValue("@contactperson", f5.Text)
        .Parameters.AddWithValue("@contactnumber", f6.Text)
        .Parameters.AddWithValue("@UserLogin", f12.Text)
        .Parameters.AddWithValue("@mDate", DateTimePicker1.Text)
        .Connection = Con

        .ExecuteNonQuery()
    End With
    If Cmd.ExecuteNonQuery() Then
        Con.Close()
        MessageBox.Show("New Record is Added successfully.", "Record Saved")
        Call clear()

    Else

        MsgBox("Could Not Insert Record!!! ", "Already Entered")
        Return
    End If
End Sub
.Parameters.AddWithValue("@mDate", DateTimePicker1.Value)