473,598 Members | 3,252 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

An unhandled exception of type 'System.Data.Sq lClient.SqlExce ption' occurred in syste

16 New Member
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.Sq lClient.SqlExce ption' occurred in system.data.dll
Additional information: System error." pls help me solve the problem...thank s..

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 4720
Plater
7,872 Recognized Expert Expert
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 Recognized Expert Specialist
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
2941
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 application that is going to be used to extract data from a legacy system (VSAM based mainframe file structure), and output data in pipe-delimited record layouts, multiple record types per file, one file per chosen client. I have been working on...
1
2372
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 and has been chosen as the deadlock victim. Rerun the transaction. at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream) at System.Data.SqlClient.SqlCommand.ExecuteXmlReader()
4
2240
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 application that is going to be used to extract data from a legacy system (VSAM based mainframe file structure), and output data in pipe-delimited record layouts, multiple record types per file, one file per chosen client. I have been working on...
2
8892
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 already exists in the database. Please change the description and try to save again." instead of
7
9525
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. The .NET 2.0 exception does give a little more info than .NET 1.1 did, but not much. Can anybody give any pointers about how to track this down? It occurs every 10 hrs around the clock, like clockwork. I have included the stack trace, but...
3
1439
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 ordinary Exception. How do I recast it to its original type without having to hard-code all different types of exceptions with "typeOf exception Is System.Data.SqlClient.SqlException" ? CType(myExp, System.Type(myExp.GetType.FullName))
3
15343
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 SqlClient.SqlConnection("Server=SOSQLSRV01;Initial Catalog=SO_Bolle;Uid=SO_CattolicaRE;PWD=sogeda") Dim iddestinatario As Integer Dim TestoQueryCodicecodicedestinario As String = "SELECT
2
2191
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 the following options is better? ----------------------------------------------------- Option 1: try{...} catch (System.Data.SqlClient.SqlException ex) { if (ex.State == 1)
1
3160
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 'System.NullReferenceException' occurred in my_deepot_common.dll Object reference not set to an instance of an obj int this line public System.Data.SqlClient.SqlConnection user_connection = new
0
7987
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7899
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8392
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8397
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
5850
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3897
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3939
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2412
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1250
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.