我正在编写一个软件,它将从一个粘性的用户那里接收信息,然后在“保存”之后将信息应用到我的SQL数据库中。按下按钮。我收到一条错误,指出"无效的列名称'客户名称'",即使我的拼写在整个文件中正确且一致,并且与我的数据库中的拼写完全相同。我已经包含括号来尝试确保在SQL中读取CustomerName并仍然收到相同的错误。我也参数化了查询,仍然没有运气。我的尝试中的例外情况告诉我它在这个区块内,但是我已经盯着它看了太长时间才能看到任何错误。有什么建议??
Else
If log = vbNullString Then
log = "No Input"
End If
Try
Dim con2 As New SqlClient.SqlConnection(ConnectString)
con2.Open()
Dim cmd As SqlClient.SqlCommand
Dim sql1 As String = "Insert Into WorkOrders (DateIn, DateTime, Problem, WhoTook, Tech, DateOut, [WONum], [BuildingRoom], [Open], [CustomerName], [CustomerPhone], [CustomerEmail], TaskType, PCProb, ProjectorProb, VisualizerProb, MicProb, SecondaryInputProb, ControlSysProb, RemoteProb, ConnectivityProb, CableProb, OtherProb, ActTaskType, ActPCProb, ActProjectorProb, ActVisualizerProb, ActMicProb, ActSecondaryInputProb, ActControlSysProb, ActRemoteProb, ActConnectivityProb, ActCableProb, ActOtherProb, EndNotes, FeedbackGrade, FeedbackComments, CompleteClosedByID, TicketLog) Values (@DateIn, @DateTime, @Problem, @WhoTook, @Tech, @DateOut, @WONum, @BuildingRoom, @Open, @CustomerName, @CustomerPhone, @CustomerEmail, @TaskType, @PCProb, @ProjectorProb, @VisualizerProb, @MicProb, @SecondaryInputProb, @ControlSysProb, @RemoteProb, @ConnectivityProb, @CableProb, @OtherProb, @ActTaskType, @ActPCProb, @ActProjectorProb, @ActVisualizerProb, @ActMicProb, @ActSecondaryInputProb, @ActControlSysProb, @ActRemoteProb, @ActConnectivityProb, @ActCableProb, @ActOtherProb, @EndNotes, @FeedbackGrade, @FeedbackComments, @CompleteClosedByID, @TicketLog)"
cmd = New SqlClient.SqlCommand(sql1, con2)
cmd.Parameters.Add("@DateIn", SqlDbType.DateTime).Value = DateIn
cmd.Parameters.Add("@DateTime", SqlDbType.DateTime).Value = TimeScheduled
cmd.Parameters.Add("@Problem", SqlDbType.NVarChar).Value = ProbTextBox.Text
cmd.Parameters.Add("@WhoTook", SqlDbType.NVarChar).Value = EmployeeBox.Text
cmd.Parameters.Add("@Tech", SqlDbType.VarChar).Value = EmployeeBox.Text
cmd.Parameters.Add("@DateOut", SqlDbType.DateTime).Value = TimeScheduled
cmd.Parameters.Add("@WONum", SqlDbType.Int).Value = WorkOrderNum
cmd.Parameters.Add("@BuildingRoom", SqlDbType.VarChar).Value = BuildingRoomTextBox.Text
cmd.Parameters.Add("@Open", SqlDbType.Bit).Value = WOOpenButton.Checked
cmd.Parameters.Add("@CustomerName", SqlDbType.VarChar).Value = CustomerNameComboBox.Text
cmd.Parameters.Add("@CustomerPhone", SqlDbType.NVarChar).Value = CustomerPhoneTextBox.Text
cmd.Parameters.Add("@CustomerEmail", SqlDbType.VarChar).Value = CustomerEmailTextBox.Text
If (String.IsNullOrEmpty(TaskType)) Then
cmd.Parameters.AddWithValue("@TaskType", DBNull.Value)
Else
cmd.Parameters.AddWithValue("@TaskType", SqlDbType.VarChar).Value = TaskType
End If
cmd.Parameters.Add("@PCProb", SqlDbType.Bit).Value = PCBox.Checked
cmd.Parameters.Add("@ProjectorProb", SqlDbType.Bit).Value = ProjectorBox.Checked
cmd.Parameters.Add("@VisualizerProb", SqlDbType.Bit).Value = VisualizerBox.Checked
cmd.Parameters.Add("@MicProb", SqlDbType.Bit).Value = MicBox.Checked
cmd.Parameters.Add("@SecondaryInputProb", SqlDbType.Bit).Value = SecondaryBox.Checked
cmd.Parameters.Add("@ControlSysProb", SqlDbType.Bit).Value = ControlBox.Checked
cmd.Parameters.Add("@RemoteProb", SqlDbType.Bit).Value = RemotesBox.Checked
cmd.Parameters.Add("@ConnectivityProb", SqlDbType.Bit).Value = ConnectivityBox.Checked
cmd.Parameters.Add("@CableProb", SqlDbType.Bit).Value = CableBox.Checked
cmd.Parameters.Add("@OtherProb", SqlDbType.Bit).Value = OtherBox.Checked
If (String.IsNullOrEmpty(TaskType)) Then
cmd.Parameters.AddWithValue("@ActTaskType", DBNull.Value)
Else
cmd.Parameters.AddWithValue("@ActTaskType", SqlDbType.VarChar).Value = ActTaskType
End If
cmd.Parameters.Add("@ActPCProb", SqlDbType.Bit).Value = ActPC.Checked
cmd.Parameters.Add("@ActProjectorProb", SqlDbType.Bit).Value = ActProjector.Checked
cmd.Parameters.Add("@ActVisualizerProb", SqlDbType.Bit).Value = ActVisualizer.Checked
cmd.Parameters.Add("@ActMicProb", SqlDbType.Bit).Value = ActMic.Checked
cmd.Parameters.Add("@ActSecondaryInputProb", SqlDbType.Bit).Value = ActSecondary.Checked
cmd.Parameters.Add("@ActControlSysProb", SqlDbType.Bit).Value = ActControl.Checked
cmd.Parameters.Add("@ActRemoteProb", SqlDbType.Bit).Value = ActRemote.Checked
cmd.Parameters.Add("@ActConnectivityProb", SqlDbType.Bit).Value = ActConnectivity.Checked
cmd.Parameters.Add("@ActCableProb", SqlDbType.Bit).Value = ActCable.Checked
cmd.Parameters.Add("@ActOtherProb", SqlDbType.Bit).Value = ActOther.Checked
cmd.Parameters.Add("@EndNotes", SqlDbType.NVarChar).Value = SolutionBox.Text
cmd.Parameters.Add("@FeedbackGrade", SqlDbType.NVarChar).Value = SolutionBox.Text
cmd.Parameters.Add("@FeedbackComments", SqlDbType.NVarChar).Value = SolutionBox.Text
cmd.Parameters.Add("@CompleteClosedByID", SqlDbType.VarChar).Value = EmployeeBox.Text
cmd.Parameters.Add("@TicketLog", SqlDbType.VarChar).Value = log
cmd.ExecuteNonQuery()
con2.Close()
If EmployeeBox.Text = vbNullString Then
EmployeeBox.Text = vbNullString
Else : WOs.AssignTech(EmployeeBox.Text)
End If
MessageBox.Show("New Record added")
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If
答案 0 :(得分:0)
另一个想法,你确定使用的连接字符串?有时您认为使用数据库而不是使用其他数据库。当connectionstring包含替换字符串| DataDirectory |时,会发生这种情况使用AttachDbFileName。 - 史蒂夫
我的connectionstring指向错误的目录。谢谢你的帮助!