468,133 Members | 1,236 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,133 developers. It's quick & easy.

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 4396
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

Post your reply

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

Similar topics

3 posts views Thread by Professor Frink | last post: by
27 posts views Thread by didacticone | last post: by
1 post views Thread by gcdp | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.