我一直有这个错误
" system.dll中发生了system.data.sqlclient.sqlexception类型的未处理异常
我似乎无法找到我失踪的东西而且它指向我的
Private Sub Check_Info()
etc..
etc...
etc.
dDA.FILL(dDS) '<<
注意: 我的SQLserver正在运行,运行连接的表也没问题。 代码
#Region " Variable Declarations "
Public sConn As SqlConnection
Dim eDS As DataSet = New DataSet
Dim eDA As SqlDataAdapter = New SqlDataAdapter
Dim eDR As DataRow
Dim dDS As DataSet = New DataSet
Dim dDA As SqlDataAdapter = New SqlDataAdapter
Dim dDR As DataRow
'Public bExitApplication As Boolean
#End Region
#Region " User-defined Procedures "
Private Sub Check_Info()
sConn.Open()
eDA.SelectCommand = New SqlCommand("SELECT emp_fname,emp_lname,emp_mname FROM tblEmployee WHERE emp_idno='" & TextBox1.Text.ToString & "' and emp_pass='" & TextBox2.Text & "'", sConn)
eDS.Clear()
eDA.Fill(eDS)
If eDS.Tables(0).Rows.Count > 0 Then
eDR = eDS.Tables(0).Rows(0)
TextBox3.Text = eDR("emp_lname") & ", " & eDR("emp_fname") & " " & eDR("emp_mname")
dDA.SelectCommand = New SqlCommand("SELECT * FROM tblDTR WHERE emp_idno='" & TextBox1.Text & "' AND date_timein=#" & Format(Now, "MM/d/yyyy") & "# AND time_timeout IS NULL", sConn)
dDS.Clear()
dDA.Fill(dDS)
If dDS.Tables(0).Rows.Count > 0 Then
dDR = dDS.Tables(0).Rows(0)
Button1.Enabled = True
Button1.Text = "&Time Out"
TextBox4.Text = Format(dDR("time_timein"), "h:mm:ss tt")
Else
Button1.Enabled = True
Button1.Text = "&Time In"
End If
dDR = Nothing
dDS.Dispose()
dDA.Dispose()
Else
TextBox3.Clear()
TextBox4.Clear()
TextBox5.Clear()
Button1.Enabled = False
End If
eDR = Nothing
eDS.Dispose()
eDA.Dispose()
sConn.Close()
End Sub
Private Sub ReturnFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox3.GotFocus, TextBox4.GotFocus, TextBox5.GotFocus
TextBox1.Focus()
End Sub
Private Sub TextboxChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged, TextBox2.TextChanged
If (TextBox1.Text <> "" And TextBox2.Text <> "") Then
Check_Info()
End If
End Sub
Private Sub LoginGotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.GotFocus, TextBox2.GotFocus
TextBox3.Clear()
TextBox4.Clear()
TextBox5.Clear()
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
sConn = New SqlConnection("Data Source=(localdb)\Projects;Initial Catalog=StudInfo;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False")
Label2.Text = Format(Now, "MMMM d, yyyy h:mm:ss tt")
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Label2.Text = Format(Now, "MMMM d, yyyy h:mm:ss tt")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Time-in and Time-out button
Dim strSQL As String
sConn.Open()
If Button1.Text = "&Time In" Then
dDR = dDS.Tables(0).NewRow()
TextBox4.Text = Format(Now, "h:mm:ss tt")
strSQL = "INSERT INTO tblDTR (emp_idno, date_timein, time_timein) VALUES ('" & TextBox1.Text & "', #" & Format(Now, "MM/d/yyyy") & "#, #" & TextBox4.Text & "#)"
Button1.Text = "&Time Out"
Else
TextBox5.Text = Format(Now, "h:mm:ss tt")
strSQL = "UPDATE tblDTR SET time_timeout=#" & TextBox5.Text & "# WHERE emp_idno='" & TextBox1.Text & "' AND date_timein=#" & Format(Now, "MM/d/yyyy") & "# and time_timein=#" & TextBox4.Text & "#"
Button1.Text = "&Time In"
End If
Dim dCmd As SqlCommand = New SqlCommand(strSQL, sConn)
dCmd.ExecuteNonQuery()
dCmd.Dispose()
dDR = Nothing
dDS.Dispose()
dDA.Dispose()
sConn.Close()
Button1.Enabled = False
TextBox1.Clear()
TextBox2.Clear()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
' clear the form
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox5.Clear()
Button1.Text = "&Time In"
Button1.Enabled = False
TextBox1.Focus()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
' System Administration
bExitApplication = True
Dim f As Form
f = New UserLogin
Me.Close()
f.Show()
End Sub
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
If Not bExitApplication Then
MsgBox("You cannot close the system this way..." & vbCrLf & vbCrLf & "Please Quit the application in the System Administration Module or by clicking Exit in the bottom of this window.", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Error: No Administrative Privilage")
e.Cancel = True
End If
End Sub
Private Sub Label7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label7.Click
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
MsgBox("Thank you for using Attandance Monitoring System")
bExitApplication = True
Application.Exit()
End Sub
End Class
答案 0 :(得分:0)
...date_timein=#" & Format(Now, "MM/d/yyyy") & "#...
你没有生成VB代码,你是生成的SQL代码,所以不要在字符串文字中使用#。正确的方法是输入一个参数:
dDA.SelectCommand = New SqlCommand("SELECT * FROM tblDTR WHERE emp_idno=@EmpID AND date_timein=@Today AND time_timeout IS NULL", sConn)
cmd.Parameters.Add("@Today",DbType.DateTime).Value = DateTime.Now
cmd.Parameters.Add("@EmpID",DbType.Int).Value = TextBox1.Text