Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/7.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
Visual studio 查询值和目标字段的数量不相同。错误消息_Visual Studio - Fatal编程技术网

Visual studio 查询值和目标字段的数量不相同。错误消息

Visual studio 查询值和目标字段的数量不相同。错误消息,visual-studio,Visual Studio,我在visual basic中的代码出现错误消息。请帮忙。谢谢 错误显示: 私有子btnAdd_Click(ByVal sender作为System.Object,ByVal e作为System.EventArgs)处理btnAdd。单击 Dim cmd作为新的OleDb.OleDbCommand If Not cnn.State = ConnectionState.Open Then cnn.Open() End If cmd.Connection = cnn If Me.txt

我在visual basic中的代码出现错误消息。请帮忙。谢谢

错误显示:

私有子btnAdd_Click(ByVal sender作为System.Object,ByVal e作为System.EventArgs)处理btnAdd。单击 Dim cmd作为新的OleDb.OleDbCommand

If Not cnn.State = ConnectionState.Open Then
    cnn.Open()
End If

cmd.Connection = cnn

If Me.txtID.Tag & "" = "" Then
    cmd.CommandText = "INSERT INTO ProfessorListTable(ID,LastName,FirstName,MI,Gender,Department,ContactNo,Address,EmailAddress,YearEmployed)" & _
        " VALUES(" & Me.txtID.Text & ",'" & Me.txtLName.Text & "','" & _
        Me.txtFName.Text & "','" & Me.txtMI.Text & "','" & _
        Me.txtGender.Text & "','" & Me.txtDept.Text & "','" & _
        Me.txtNo.Text & "','" & Me.txtAddress.Text & "','" & _
        Me.txtEAdd.Text & "','" & Me.txtYear.Text & "',')"

    cmd.ExecuteNonQuery()
Else
    cmd.CommandText = "UPDATE ProfessorListTable " & _
    " SET txtID=" & Me.txtID.Text & _
    ", LastName='" & Me.txtLName.Text & "'" & _
    ", FirstName='" & Me.txtFName.Text & "'" & _
    ", MI='" & Me.txtMI.Text & "'" & _
    ", Gender='" & Me.txtGender.Text & "'" & _
    ", Department='" & Me.txtDept.Text & "'" & _
    ", ContactNo='" & Me.txtNo.Text & _
    ", Address='" & Me.txtAddress.Text & "'" & _
    ", EmailAddress='" & Me.txtEAdd.Text & "'" & _
    ", YearEmployed='" & Me.txtYear.Text & _
    " WHERE stdid=" & Me.txtID.Tag
    cmd.ExecuteNonQuery()


End If


RefreshData()
端接头

这里有多余的逗号(,)

所以它的值是11,而不是10

地址是保留字,所以用它作为[地址]

像这样试试

Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click Dim cmd As New OleDb.OleDbCommand

If Not cnn.State = ConnectionState.Open Then
    cnn.Open()
End If

cmd.Connection = cnn

If Me.txtID.Tag & "" = "" Then
    cmd.CommandText = "INSERT INTO ProfessorListTable(ID,LastName,FirstName,MI,Gender,Department,ContactNo,[Address],EmailAddress,YearEmployed)" & _
        " VALUES(" & Me.txtID.Text & ",'" & Me.txtLName.Text & "','" & _
        Me.txtFName.Text & "','" & Me.txtMI.Text & "','" & _
        Me.txtGender.Text & "','" & Me.txtDept.Text & "','" & _
        Me.txtNo.Text & "','" & Me.txtAddress.Text & "','" & _
        Me.txtEAdd.Text & "','" & Me.txtYear.Text & "')"

    cmd.ExecuteNonQuery()
Else
    cmd.CommandText = "UPDATE ProfessorListTable " & _
    " SET txtID=" & Me.txtID.Text & _
    ", LastName='" & Me.txtLName.Text & "'" & _
    ", FirstName='" & Me.txtFName.Text & "'" & _
    ", MI='" & Me.txtMI.Text & "'" & _
    ", Gender='" & Me.txtGender.Text & "'" & _
    ", Department='" & Me.txtDept.Text & "'" & _
    ", ContactNo='" & Me.txtNo.Text & _
    ", [Address]='" & Me.txtAddress.Text & "'" & _
    ", EmailAddress='" & Me.txtEAdd.Text & "'" & _
    ", YearEmployed='" & Me.txtYear.Text & _
    " WHERE stdid=" & Me.txtID.Tag
    cmd.ExecuteNonQuery()


End If
RefreshData()
End Sub

非常感谢。我又犯了一个错误。它说:SELECT语句包含一个保留字或一个拼写错误或缺少的参数名,或者标点符号不正确。Address是保留关键字,所以像[Address]一样使用。我尝试使用[Address],但它显示了相同的错误。有关更详细的错误消息,请参阅。请看这个,非常感谢
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click Dim cmd As New OleDb.OleDbCommand

If Not cnn.State = ConnectionState.Open Then
    cnn.Open()
End If

cmd.Connection = cnn

If Me.txtID.Tag & "" = "" Then
    cmd.CommandText = "INSERT INTO ProfessorListTable(ID,LastName,FirstName,MI,Gender,Department,ContactNo,[Address],EmailAddress,YearEmployed)" & _
        " VALUES(" & Me.txtID.Text & ",'" & Me.txtLName.Text & "','" & _
        Me.txtFName.Text & "','" & Me.txtMI.Text & "','" & _
        Me.txtGender.Text & "','" & Me.txtDept.Text & "','" & _
        Me.txtNo.Text & "','" & Me.txtAddress.Text & "','" & _
        Me.txtEAdd.Text & "','" & Me.txtYear.Text & "')"

    cmd.ExecuteNonQuery()
Else
    cmd.CommandText = "UPDATE ProfessorListTable " & _
    " SET txtID=" & Me.txtID.Text & _
    ", LastName='" & Me.txtLName.Text & "'" & _
    ", FirstName='" & Me.txtFName.Text & "'" & _
    ", MI='" & Me.txtMI.Text & "'" & _
    ", Gender='" & Me.txtGender.Text & "'" & _
    ", Department='" & Me.txtDept.Text & "'" & _
    ", ContactNo='" & Me.txtNo.Text & _
    ", [Address]='" & Me.txtAddress.Text & "'" & _
    ", EmailAddress='" & Me.txtEAdd.Text & "'" & _
    ", YearEmployed='" & Me.txtYear.Text & _
    " WHERE stdid=" & Me.txtID.Tag
    cmd.ExecuteNonQuery()


End If
RefreshData()
End Sub