An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chaudharis57
    New Member
    • Feb 2014
    • 1

    An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred

    Code:
    Imports System.Data
    Imports System.Data.SqlClient
    
    
    Public Class LoginForm1
        
        Dim da As SqlDataAdapter
        Dim ds As DataSet
        Dim query As String
        Dim sqlq As String
    
        Private Sub DELETETIME()
            If con.State = ConnectionState.Open Then con.Close()
            con.Open()
    
            
            query = "DELETE FROM USERLOG WHERE USERID='" & USERNAME & "'"
    
            COMMAND = New SqlCommand(query, con)
            COMMAND.ExecuteNonQuery()
    
        End Sub
    
    
        
        Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
            Dim CMD As SqlCommand
            If con.State = ConnectionState.Open Then con.Close()
            con.Open()
    
            query = "select * from USERLOGIN where USERID='" & txtUsername.Text & "'and UPASSWORD='" & txtPasswd.Text & "'"
    
            da = New SqlDataAdapter(query, con)
            ds = New DataSet
            da.Fill(ds)
            If ds.Tables(0).Rows.Count > 0 Then
                'valid user
                USERNAME = txtUsername.Text
    
                USERTYPE = ds.Tables(0).Rows(0).Item(3)
                logintime = Now
                DELETETIME()
    
                If con.State = ConnectionState.Open Then con.Close()
                con.Open()
    
                'query = "UPDATE USERLOG SET ULOGDATE='" & Today & "',ULOGINTIME='" & Now & "' WHERE USERID='" & USERNAME & "'"
                query = "INSERT INTO USERLOG VALUES('" & txtUsername.Text & "','" & Today & "','" & Now.TimeOfDay.ToString & "')"
    
                CMD = New SqlCommand(query, con)
                CMD.ExecuteNonQuery()
    
    
                con.Open()
                
    
                con.Close()
    
    
                frmMDIMain.Show()
                Me.Hide()
    
    
            Else
                MsgBox("INVALID LOGIN")
                
            End If
    
            txtUsername.Text = ""
            txtPasswd.Text = ""
            txtUsername.Focus()
    
    
        End Sub
    
        Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            'Me.Close()
            End
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            txtUsername.Text = ""
            txtPasswd.Text = ""
            txtUsername.Focus()
    
        End Sub
    
        Private Sub LoginForm1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Call myConnection()
            txtUsername.Focus()
    
        End Sub
    
        
    End Class
    when I try to run this program one pop window is arise.

    plz tell me how can I over come from this error.

    thanx in advance
    Attached Files
Working...