By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,987 Members | 971 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,987 IT Pros & Developers. It's quick & easy.

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

P: 1
Expand|Select|Wrap|Line Numbers
  1. Imports System.Data
  2. Imports System.Data.SqlClient
  3.  
  4.  
  5. Public Class LoginForm1
  6.  
  7.     Dim da As SqlDataAdapter
  8.     Dim ds As DataSet
  9.     Dim query As String
  10.     Dim sqlq As String
  11.  
  12.     Private Sub DELETETIME()
  13.         If con.State = ConnectionState.Open Then con.Close()
  14.         con.Open()
  15.  
  16.  
  17.         query = "DELETE FROM USERLOG WHERE USERID='" & USERNAME & "'"
  18.  
  19.         COMMAND = New SqlCommand(query, con)
  20.         COMMAND.ExecuteNonQuery()
  21.  
  22.     End Sub
  23.  
  24.  
  25.  
  26.     Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
  27.         Dim CMD As SqlCommand
  28.         If con.State = ConnectionState.Open Then con.Close()
  29.         con.Open()
  30.  
  31.         query = "select * from USERLOGIN where USERID='" & txtUsername.Text & "'and UPASSWORD='" & txtPasswd.Text & "'"
  32.  
  33.         da = New SqlDataAdapter(query, con)
  34.         ds = New DataSet
  35.         da.Fill(ds)
  36.         If ds.Tables(0).Rows.Count > 0 Then
  37.             'valid user
  38.             USERNAME = txtUsername.Text
  39.  
  40.             USERTYPE = ds.Tables(0).Rows(0).Item(3)
  41.             logintime = Now
  42.             DELETETIME()
  43.  
  44.             If con.State = ConnectionState.Open Then con.Close()
  45.             con.Open()
  46.  
  47.             'query = "UPDATE USERLOG SET ULOGDATE='" & Today & "',ULOGINTIME='" & Now & "' WHERE USERID='" & USERNAME & "'"
  48.             query = "INSERT INTO USERLOG VALUES('" & txtUsername.Text & "','" & Today & "','" & Now.TimeOfDay.ToString & "')"
  49.  
  50.             CMD = New SqlCommand(query, con)
  51.             CMD.ExecuteNonQuery()
  52.  
  53.  
  54.             con.Open()
  55.  
  56.  
  57.             con.Close()
  58.  
  59.  
  60.             frmMDIMain.Show()
  61.             Me.Hide()
  62.  
  63.  
  64.         Else
  65.             MsgBox("INVALID LOGIN")
  66.  
  67.         End If
  68.  
  69.         txtUsername.Text = ""
  70.         txtPasswd.Text = ""
  71.         txtUsername.Focus()
  72.  
  73.  
  74.     End Sub
  75.  
  76.     Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  77.         'Me.Close()
  78.         End
  79.     End Sub
  80.  
  81.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  82.         txtUsername.Text = ""
  83.         txtPasswd.Text = ""
  84.         txtUsername.Focus()
  85.  
  86.     End Sub
  87.  
  88.     Private Sub LoginForm1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  89.         Call myConnection()
  90.         txtUsername.Focus()
  91.  
  92.     End Sub
  93.  
  94.  
  95. End Class
  96.  
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 Images
File Type: jpg sqlerror.jpg (41.9 KB, 93 views)
Feb 24 '14 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.

Browse more Visual Basic .NET Questions on Bytes