472,950 Members | 2,533 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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

16
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 information: System error." pls help me solve the problem...thanks..

my code:
Expand|Select|Wrap|Line Numbers
  1. Imports System.Data.SqlClient
  2. Imports System.Data.OleDb
  3. Imports System.Globalization
  4. Imports System.Threading
  5.  
  6. Public Class PhoneBook
  7.     Inherits System.Windows.Forms.Form
  8.  
  9.     Private lsFORMTEXT As String
  10.     Private lsFINDNAME1, lsFINDNAME2 As String
  11.     Private lsMODE1 As String
  12.     Private lsCONSTRSIM, lsCONSTRCSV As String
  13.     Private lsUSRCODE As String
  14.     Private lsSQL As String
  15.     Private oBUTTON As Object
  16.     Private oMENU As Object
  17.     Private liBUTTON As Integer
  18.     Private liMENU As Integer
  19.  
  20.     Private lsSQLSTR As String
  21.     Private lsSQLCON As SqlConnection
  22.  
  23.     Private lsSQLCMD1 As SqlCommand
  24.     Private lsSQLCBL1 As SqlCommandBuilder
  25.     Private lsDA1 As SqlDataAdapter
  26.     Private lsDS1 As DataSet
  27.     Private lsDT1 As DataTable
  28.     Private lsDR As DataRow
  29.  
  30.     Private lsTABLE1 As String = "PhoneBook"
  31.     Private lsKEY As String = "Name"
  32.  
  33.     Private cls1 As New clsCon
  34.  
  35.     Private liLOOP1 As Integer
  36.     Private liCR As Integer
  37.     Private liANS As Integer
  38.  
  39.     Private lsTEXTBOX(2) As TextBox
  40.     Private lsTEXTBOXNUMBER(0) As TextBox
  41.     Private lsTEXTBOXINT(2) As TextBox
  42.     Private lsCOMBOBOX(1) As ComboBox
  43.  
  44.     Private cTEXTBOX(2) As String
  45.     Private cTEXTBOXNUMBER(0) As String
  46.     Private cTEXTBOXINT(2) As String
  47.     Private cCOMBOBOX(1) As String
  48.  
  49.     Private liTEXTBOX As Integer = 2
  50.     Private liTEXTBOXNUMBER As Integer = 0
  51.     Private liTEXTBOXINT As Integer = 2
  52.     Private liCOMBOBOX As Integer = 1
  53.  
  54.     Private lsBUTTON(0) As Object
  55.     Private lsMENU(0) As Object
  56.  
  57.     Private Sub PhoneBook_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  58.         lsCONSTRCSV = cls1.SetupText()
  59.         Me.Text = lsFORMTEXT
  60.         lbl_gsmode1.Text = lsMODE1
  61.         lsMODE1 = "VIEW"
  62.         IniObject()
  63.         DataPopulate()
  64.         DataBindClear()
  65.         DataBind()
  66.         DataDisplay()
  67.     End Sub
  68.  
  69.     Private Sub IniObject()
  70.         lsTEXTBOX(1) = txt_Name
  71.         lsTEXTBOX(2) = txt_Address
  72.         lsTEXTBOXINT(1) = txt_Phone
  73.         lsTEXTBOXINT(2) = txt_Code
  74.         lsCOMBOBOX(1) = cbo_State
  75.  
  76.         cTEXTBOX(1) = "Name"
  77.         cTEXTBOX(2) = "Address"
  78.         cTEXTBOXINT(1) = "PhoneNumber"
  79.         cTEXTBOXINT(2) = "PostalCode"
  80.         cCOMBOBOX(1) = "State"
  81.  
  82.     End Sub
  83.  
  84.     Private Sub DataPopulate()
  85.         lsSQLSTR = "SELECT * FROM" & lsTABLE1 & "ORDER BY " & lsKEY
  86.         lsSQLCON = New SqlConnection(lsCONSTRCSV)
  87.         Dim lsSQLCMD1 As New SqlCommand(lsSQLSTR, lsSQLCON)
  88.         lsDA1 = New SqlDataAdapter(lsSQLCMD1)
  89.         Dim lsSQLCMB1 As New SqlCommandBuilder(lsDA1)
  90.         lsSQLCMB1.GetUpdateCommand()  -->'error at here'
  91.  
  92.         lsDS1 = New DataSet
  93.         lsDT1 = New DataTable
  94.         lsDA1.Fill(lsDS1, lsTABLE1)
  95.         lsDT1 = lsDS1.Tables(0)
  96.         lsDT1.DefaultView.Sort = lsKEY
  97.     End Sub
  98.  
  99.     Private Sub DataBindClear()
  100.         cls1.Get_DataBindClear(liTEXTBOX, lsTEXTBOX, cTEXTBOX, liTEXTBOXNUMBER, lsTEXTBOXNUMBER, cTEXTBOXNUMBER, liTEXTBOXINT, lsTEXTBOXINT, cTEXTBOXINT, liCOMBOBOX, lsCOMBOBOX, cCOMBOBOX)
  101.     End Sub
  102.  
  103.     Private Sub DataBind()
  104.         cls1.Get_DataBind(liTEXTBOX, lsTEXTBOX, cTEXTBOX, liTEXTBOXNUMBER, lsTEXTBOXNUMBER, cTEXTBOXNUMBER, liTEXTBOXINT, lsTEXTBOXINT, cTEXTBOXINT, liCOMBOBOX, lsCOMBOBOX, cCOMBOBOX, lsDT1)
  105.     End Sub
  106.  
  107.     Private Sub DataClear()
  108.         cls1.Get_DataClear(liTEXTBOX, lsTEXTBOX, cTEXTBOX, liTEXTBOXNUMBER, lsTEXTBOXNUMBER, cTEXTBOXNUMBER, liTEXTBOXINT, lsTEXTBOXINT, cTEXTBOXINT, liCOMBOBOX, lsCOMBOBOX, cCOMBOBOX)
  109.     End Sub
  110.  
  111.     Private Sub DataDisplay()
  112.         cls1.Get_DataDisplay(liTEXTBOX, lsTEXTBOX, cTEXTBOX, liTEXTBOXNUMBER, lsTEXTBOXNUMBER, cTEXTBOXNUMBER, liTEXTBOXINT, lsTEXTBOXINT, cTEXTBOXINT, liCOMBOBOX, lsCOMBOBOX, cCOMBOBOX, lsMODE1)
  113.         lsTEXTBOX(1).Enabled = IIf(lsMODE1 = "VIEW" Or lsMODE1 = "MODIFY", False, True)
  114.     End Sub
  115.  
  116.     Private Sub btn_back_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_back.Click
  117.         If Me.BindingContext(lsDT1).Position <> 0 Then
  118.             Me.BindingContext(lsDT1).Position -= 1
  119.         End If
  120.     End Sub
  121.  
  122.     Private Sub btn_next_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_next.Click
  123.         If Me.BindingContext(lsDT1).Position < lsDT1.Rows.Count - 1 Then
  124.             Me.BindingContext(lsDT1).Position += 1
  125.         End If
  126.     End Sub
  127.  
  128.     Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnu_File_Close.Click
  129.         Me.Close()
  130.     End Sub
  131.  
  132.     Private Sub btn_Find_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Find.Click
  133.         Try
  134.             Dim lsHT(1) As Object
  135.             Dim lsDT1c As New DataTable
  136.             lsHT(0) = "1"
  137.             lsHT(1) = Trim("Name") & "01001"
  138.             lsDT1c = lsDT1.Copy
  139.  
  140.             Dim frmFind As New foFIND(lsDT1c, lsHT, lsFINDNAME1)
  141.             lsFINDNAME1 = lsTEXTBOX(1).Text
  142.             frmFind.ShowDialog()
  143.             lsFINDNAME1 = cls1.FindPro
  144.             If Len(Trim(lsFINDNAME1)) > 0 Then
  145.                 Dim lsFINDKEY(1) As Object
  146.                 lsFINDKEY(0) = "1"
  147.                 lsFINDKEY(1) = Trim(lsFINDNAME1)
  148.                 liCR = cls1.GetRecordPosition(lsDT1, lsKEY, lsFINDKEY)
  149.                 If liCR >= 0 Then
  150.                     DataBindClear()
  151.                     DataBind()
  152.                     DataDisplay()
  153.                     Me.BindingContext(lsDT1).Position = liCR
  154.                 End If
  155.             End If
  156.             lsDT1c.Dispose()
  157.         Catch exp As Exception
  158.             MsgBox(exp.Message)
  159.         End Try
  160.     End Sub
  161.  
  162.     Private Sub btn_modify_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Modify.Click
  163.         lsMODE1 = "MODIFY"
  164.         lbl_gsmode1.Text = lsMODE1
  165.         DataBindClear()
  166.         DataDisplay()
  167.         GetTwnReg()
  168.         lsTEXTBOX(2).Focus()
  169.     End Sub
  170.  
  171.     Private Sub btn_Add_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Add.Click
  172.         lsMODE1 = "ADD"
  173.         lbl_gsmode1.Text = lsMODE1
  174.         DataClear()
  175.         DataBindClear()
  176.         DataDisplay()
  177.         GetTwnReg()
  178.         lsTEXTBOX(1).Focus()
  179.     End Sub
  180.  
  181.     Private Sub GetTwnReg()
  182.         If lsMODE1 = "ADD" Or lsMODE1 = "MODIFY" Then
  183.             txt_Name.Visible = True
  184.             txt_Address.Visible = True
  185.             txt_Phone.Visible = True
  186.             txt_Code.Visible = True
  187.             cbo_State.Visible = True
  188.         Else
  189.             txt_Name.Visible = False
  190.             txt_Address.Visible = False
  191.             txt_Phone.Visible = False
  192.             txt_Code.Visible = False
  193.             cbo_State.Visible = False
  194.         End If
  195.     End Sub
  196.  
  197.     Private Sub btn_Delete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Delete.Click
  198.         Try
  199.             lsMODE1 = "DELETE"
  200.             lbl_gsmode1.Text = lsMODE1
  201.             liCR = Me.BindingContext(lsDT1).Position
  202.             liANS = MsgBox("Confirm to delete " & lsDT1.Rows(liCR).Item(lsKEY) & "?", MsgBoxStyle.YesNo, "System Dialog")
  203.             If liANS = 6 Then
  204.                 lsDT1.Rows(liCR).Delete()
  205.                 lsDA1.Update(lsDS1, lsTABLE1)
  206.             End If
  207.         Catch exp As Exception
  208.             MsgBox(exp.Message)
  209.             lsDT1.RejectChanges()
  210.             Exit Sub
  211.         Catch exp As SqlException
  212.             MsgBox(exp.Message)
  213.             lsDT1.RejectChanges()
  214.             Exit Sub
  215.         End Try
  216.         lsMODE1 = "VIEW"
  217.         lbl_gsmode1.Text = lsMODE1
  218.         DataDisplay()
  219.  
  220.     End Sub
  221. End Class
Nov 6 '08 #1
2 4671
Plater
7,872 Expert 4TB
Well I would think that the error message woul tell you more, as well as giving you the line number that caused the error.
I will say that you SQL SELECT statement looks like its missing some spaces (like after the FROM, youwould have like FROMmyTableName instead of FROM myTableName)
Nov 6 '08 #2
Curtis Rutland
3,256 Expert 2GB
Please enclose your posted code in [CODE] [/CODE] tags (See How to Ask a Question).

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use [CODE] [/CODE] tags in future.

MODERATOR
Nov 6 '08 #3

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

Similar topics

3
by: Professor Frink | last post by:
First off, I apologize if this gets long. I'm simply trying to give you all enough information to help me out. I'm writing (almost finished, actually), my first VB.Net application. It's a forms...
1
by: Adam Smith | last post by:
When executing ExecuteXmlReader() against a table where records are being inserted, I get: 9/5/2003 8:39:47 AM Transaction (Process ID 66) was deadlocked on lock resources with another process...
4
by: Craig831 | last post by:
First off, I apologize if this gets long. I'm simply trying to give you all enough information to help me out. I'm writing (almost finished, actually), my first VB.Net application. It's a forms...
2
by: James Cooke | last post by:
Hi all, I want to catch a duplicate key exception. I do not want to provide that verbose message from the MSSQL server - I would put a user friendly message out, like "The item you have added...
7
by: Alan Pretre | last post by:
I have an application installed at a customer site that has been getting a general network error for a couple of years. I was hoping that .NET 2.0 would clear it up, but unfortunately it didn't. ...
3
by: Jonas | last post by:
Hi! I have a general error logging routine that takes a parameter of type Exception. But if I send in a SqlException, I loose all the Sql-specific information as the variable is casted to an...
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...
2
by: Carol | last post by:
Exception may be thrown in the code inside the try block. I want to handling the SqlException with State == 1 in a special way, and for all others I want to use a general way to handle. Which of...
1
by: Pedro Dinis | last post by:
i have this class library that connects to the database(see appconfig below) compiling 0 errors but when its running i amhaving this error An unhandled exception of type...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...

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.