473,396 Members | 1,995 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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, 102 views)
Feb 24 '14 #1
0 1138

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

Similar topics

0
by: NicK chlam via DotNetMonster.com | last post by:
this is the error i get System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement. at System.Data.Common.DbDataAdapter.Update(DataRow dataRows, DataTableMapping tableMapping) at...
0
by: Ersin Gençtürk | last post by:
we are getting : System.Web.HttpUnhandledException: Exception of type System.Web.HttpUnhandledException was thrown. ---> System.Data.SqlClient.SqlException: Timeout expired. The timeout period...
1
by: HK | last post by:
I just moved an ASP.NET application to a new web server at a different location of ours. The SQL Server machine was moved to that new location at the same time as the web site DNS was pointed to...
5
by: Rod | last post by:
I have a client site where the code below has been working happily for at least four months. The site is using SQL Server 7. The code is ASP.NET Last week an error appeared related to the...
3
by: Rampa | last post by:
hello! the problem is always the same but i can't understand why it happens!! Someone can help me? FIRST QUERY GOES WELL, SECOND BREAK WITH ERROR why? Dim connessione As New...
1
by: weird0 | last post by:
System.Data.SqlClient.SqlException: An attempt to attach an auto- named database for file "Location" failed. A database with the same name exists, or specified file cannot be opened, or it is...
3
by: weird0 | last post by:
This is the exception that I get when i create a webserivce obj and call. The error comes on the webmethod call, when it opens a connection to the db. How do I fix it? What is the solution to...
3
by: hathan | last post by:
Can anyone explain why this code doesnt delete from the database. Some times it works and some times it errors i am confused. Private Sub DeleteBtn_Click(ByVal sender As System.Object, ByVal e As...
1
by: thithi | last post by:
Please help me " System.Data.SqlClient.SqlException: Prepared statement '(@Name varchar(100),@Describes varchar(100),@Money char(10))Upda' expects parameter @Describes, which was not supplied. at...
2
by: lily86 | last post by:
i'm very new so i hope all of u can help me. when i debug my webforms this error occur "An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll Additional...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.