Results 1 to 38 of 38

Thread: [RESOLVED] 'System.Data.SqlClient.SqlException'

  1. #1

    Thread Starter
    Addicted Member Golfreak's Avatar
    Join Date
    Oct 2005
    Location
    stuck in a cube
    Posts
    147

    Resolved [RESOLVED] 'System.Data.SqlClient.SqlException'

    hey guys

    just wondering if anyone can help. I'm getting this error:

    VB Code:
    1. An unhandled exception of type [B]System.Data.SqlClient.SqlException [/B] occurred in system.data.dll
    2.  
    3. Additional information: System error.

    and it occurs in this Sub: (in red)

    VB Code:
    1. Public Sub UpdateCombo()
    2.  
    3.         Dim RSAllCategories As SqlClient.SqlDataReader
    4.  
    5.         SqlUpdateCommand1.CommandText = "Exec ProblemCategoryList"
    6.         [COLOR=Red]RSAllCategories = SqlUpdateCommand1.ExecuteReader()[/COLOR]
    7.        
    8.         Do Until RSAllCategories.IsClosed
    9.  
    10.             cmbSelect.Items.Add(RSAllCategories.GetValue("ProblemCategory").Value)
    11.             RSAllCategories.NextResult()
    12.  
    13.         Loop
    14.  
    15.     End Sub

    whats wrong with the code?
    Last edited by Golfreak; Oct 20th, 2005 at 09:13 AM.

  2. #2
    Fanatic Member
    Join Date
    May 2003
    Posts
    758

    Re: 'System.Data.SqlClient.SqlException'

    Which line is giving you the error? Does ProblemCategoryList really exist in the DB? Does it require a parameter and you aren't passing it?

    One thing I do when I get that cryptic message is start up Profiler and watch to see exactly what the application is passing to SQL Server. That usually gives a good idea of what is happening. If I can't figure it all out from there, I copy the necessary lines from Profiler into Query Analyzer to test it from there. QA seems to give a lot better information about errors.

  3. #3
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416

    Re: 'System.Data.SqlClient.SqlException'

    Try to remove the 'Exec' in your commandtext

    SqlUpdateCommand1.CommandText = "ProblemCategoryList"

    and be sure on what commandtype is that.

    SqlUpdateCommand1.CommandType = CommandType.StoredProcedure

  4. #4

    Thread Starter
    Addicted Member Golfreak's Avatar
    Join Date
    Oct 2005
    Location
    stuck in a cube
    Posts
    147

    Re: 'System.Data.SqlClient.SqlException'

    Thanks guys for reponding to my problem. Yesterday right after posting I had to run.

    To answer ASPNOT, yes ProblemCategoryList is a stored proceedure in the DB and as for mar zim, I tried your suggestion and came up with the same error.

    VB Code:
    1. An unhandled exception of type System.Data.SqlClient.SqlException  occurred in system.data.dll
    2.  
    3. Additional information: System error.

    My code now looks like this (error in RED):

    VB Code:
    1. Public Sub UpdateCombo()
    2.  
    3.         Dim RSAllCategories As SqlClient.SqlDataReader
    4.  
    5.         SqlUpdateCommand1.CommandText = "ProblemCategoryList"
    6.         SqlUpdateCommand1.CommandType = CommandType.StoredProcedure
    7.         [COLOR=Red]RSAllCategories = SqlUpdateCommand1.ExecuteReader()[/COLOR]
    8.  
    9.        Do Until RSAllCategories.IsClosed
    10.  
    11.             cmbSelect.Items.Add(RSAllCategories.GetValue("ProblemCategory").Value)
    12.             RSAllCategories.NextResult()
    13.  
    14.         Loop
    15.  
    16.     End Sub

    Any Suggestions?????

  5. #5
    Fanatic Member
    Join Date
    May 2003
    Posts
    758

    Re: 'System.Data.SqlClient.SqlException'

    Just to make sure, you are creating a connection object and associating it with the command object, right? Does the Stored Procedure require any parameters to be passed in?

  6. #6

    Thread Starter
    Addicted Member Golfreak's Avatar
    Join Date
    Oct 2005
    Location
    stuck in a cube
    Posts
    147

    Re: 'System.Data.SqlClient.SqlException'

    I am not sure I completely follow. I am kinda new to this field. Here is the stored proceedure:

    CREATE PROCEDURE ProblemCategoryList

    AS
    BEGIN
    SELECT * FROM ProblemCategories

    ORDER BY ProblemCategory

    END
    GO

  7. #7
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: 'System.Data.SqlClient.SqlException'

    Do this, it'll tell you exactly what is wrong:

    VB Code:
    1. Try
    2.   RSAllCategories = SqlUpdateCommand1.ExecuteReader()
    3. Catch sqlex as SqlClient.SQLException
    4.   MessageBox.Show sqlex.ToString
    5. Catch ex as SystemException '<-- I think this is right
    6.   MessageBox.Show ex.ToString
    7. End Try

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #8

    Thread Starter
    Addicted Member Golfreak's Avatar
    Join Date
    Oct 2005
    Location
    stuck in a cube
    Posts
    147

    Re: 'System.Data.SqlClient.SqlException'

    Thanks techgnome

    I tried it out and got this error:

    VB Code:
    1. System.Data.SqlClient.SqlException: Proceedure ProblemCategoryList has no parameters and arguments were supplied.
    2.   at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream)
    3.   atSystem.Data.SqlClient.SqlCommand.ExecuteReader()
    4.   at HD1.frmProblemCategories.UpdateCombo() vb:line231

  9. #9

    Thread Starter
    Addicted Member Golfreak's Avatar
    Join Date
    Oct 2005
    Location
    stuck in a cube
    Posts
    147

    Re: 'System.Data.SqlClient.SqlException'

    What the heck does that mean???

  10. #10
    Frenzied Member Asgorath's Avatar
    Join Date
    Sep 2004
    Location
    Saturn
    Posts
    2,036

    Re: 'System.Data.SqlClient.SqlException'

    Try this
    VB Code:
    1. Public Sub UpdateCombo()
    2.  
    3.         Dim RSAllCategories As SqlClient.SqlDataReader
    4.  
    5.         SqlUpdateCommand1.CommandText = "ProblemCategoryList"
    6.         SqlUpdateCommand1.CommandType = CommandType.StoredProcedure
    7.         SqlUpdateCommand1.Parameters.Clear
    8.         RSAllCategories = SqlUpdateCommand1.ExecuteReader()
    9.  
    10.        Do Until RSAllCategories.IsClosed
    11.  
    12.             cmbSelect.Items.Add(RSAllCategories.GetValue("ProblemCategory").Value)
    13.             RSAllCategories.NextResult()
    14.  
    15.         Loop
    16.  
    17.     End Sub
    Regards
    Jorge
    "The dark side clouds everything. Impossible to see the future is."

  11. #11

    Thread Starter
    Addicted Member Golfreak's Avatar
    Join Date
    Oct 2005
    Location
    stuck in a cube
    Posts
    147

    Re: 'System.Data.SqlClient.SqlException'

    Hey Asgorath

    Thanks for the input

    Unfortunately, my code is full of errors here is my next one:

    VB Code:
    1. An unhandled exception of type 'System.InvalidCastException' occurred in microsoft.visualbasic.dll
    2.  
    3. Additional information: Cast from string "ProblemCategory" to type 'Integer' is not valid.

    And it hits on the line that is Bolded:

    VB Code:
    1. Public Sub UpdateCombo()
    2.  
    3.         Dim RSAllCategories As SqlClient.SqlDataReader
    4.  
    5.         SqlUpdateCommand1.CommandText = "ProblemCategoryList"
    6.         SqlUpdateCommand1.CommandType = CommandType.StoredProcedure
    7.         SqlUpdateCommand1.Parameters.Clear()
    8.         RSAllCategories = SqlUpdateCommand1.ExecuteReader()
    9.         cmbSelect.Items.Clear()
    10.  
    11.         Do Until RSAllCategories.IsClosed
    12.  
    13.            [B] cmbSelect.Items.Add(RSAllCategories.GetValue("ProblemCategory").Value)[/B]            
    14.               RSAllCategories.NextResult()
    15.  
    16.         Loop
    17.  
    18.     End Sub

  12. #12

    Thread Starter
    Addicted Member Golfreak's Avatar
    Join Date
    Oct 2005
    Location
    stuck in a cube
    Posts
    147

    Re: 'System.Data.SqlClient.SqlException'

    I have this same problem on some of my other forms.

    I think if I can get through this one, I will be close to making the whole thing work.

    Anybody have a suggestion?

  13. #13
    Frenzied Member Asgorath's Avatar
    Join Date
    Sep 2004
    Location
    Saturn
    Posts
    2,036

    Re: 'System.Data.SqlClient.SqlException'

    I don't know how may columns your problemcaterogies table has but i am assuming your only interested in the 1st collumn.

    VB Code:
    1. Public Sub UpdateCombo()
    2.  
    3.         Dim RSAllCategories As SqlClient.SqlDataReader
    4.  
    5.         SqlUpdateCommand1.CommandText = "ProblemCategoryList"
    6.         SqlUpdateCommand1.CommandType = CommandType.StoredProcedure
    7.         SqlUpdateCommand1.Parameters.Clear()
    8.         RSAllCategories = SqlUpdateCommand1.ExecuteReader()
    9.         cmbSelect.Items.Clear()
    10.  
    11.         Do Until RSAllCategories.IsClosed
    12.  
    13.             cmbSelect.Items.Add(RSAllCategories.GetValue(0).Value)            
    14.               RSAllCategories.NextResult()
    15.  
    16.         Loop
    17.  
    18.     End Sub

    Regards
    Jorge
    "The dark side clouds everything. Impossible to see the future is."

  14. #14
    Frenzied Member Asgorath's Avatar
    Join Date
    Sep 2004
    Location
    Saturn
    Posts
    2,036

    Re: 'System.Data.SqlClient.SqlException'

    as a addenda
    RSAllCategories.GetValue(0).Value is equivalent to RSAllCategories(0)

    Regards
    Jorge
    "The dark side clouds everything. Impossible to see the future is."

  15. #15

    Thread Starter
    Addicted Member Golfreak's Avatar
    Join Date
    Oct 2005
    Location
    stuck in a cube
    Posts
    147

    Re: 'System.Data.SqlClient.SqlException'

    thanks again
    now theres a new error:

    VB Code:
    1. An unhandled exception of type 'System.InvalidOperationException' occurred in system.data.dll
    2.  
    3. Additional information: Invalid attempt to read when no data is present.

    heres the code with error BOLDED:

    VB Code:
    1. Do Until RSAllCategories.IsClosed
    2.  
    3.             [B]cmbSelect.Items.Add(RSAllCategories(0))[/B]
    4.             RSAllCategories.NextResult()
    5.  
    6.         Loop
    7.  
    8.     End Sub

    Does that mean it can't read the DB?

  16. #16

    Thread Starter
    Addicted Member Golfreak's Avatar
    Join Date
    Oct 2005
    Location
    stuck in a cube
    Posts
    147

    Re: 'System.Data.SqlClient.SqlException'

    Like I said, I'm new to the programming world and especially to VB.net

    I am beginning to think I built the whole thing incorrectly

  17. #17
    Frenzied Member Asgorath's Avatar
    Join Date
    Sep 2004
    Location
    Saturn
    Posts
    2,036

    Re: 'System.Data.SqlClient.SqlException'

    Strange run your stored procedure in query analyser to see if it returns any row.

    Regards
    Jorge
    "The dark side clouds everything. Impossible to see the future is."

  18. #18
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: 'System.Data.SqlClient.SqlException'

    I wondered about that.... the loop is bad....

    RSAllCategories.IsClosed - the connection is still open, so this will continue to run, even after you run out of values.

    VB Code:
    1. Do While RSAllCategories.Read
    2.             cmbSelect.Items.Add(RSAllCategories(0))
    3.         Loop

    .Read will return true as long as there is something in the reader to read. It also has the added bonus of moving to the next record automatically if there is one.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  19. #19

    Thread Starter
    Addicted Member Golfreak's Avatar
    Join Date
    Oct 2005
    Location
    stuck in a cube
    Posts
    147

    Re: 'System.Data.SqlClient.SqlException'

    Thanks Techgnome

    That solved a ton of my problems.

    I have more but I think I can get it from here.

    If not then I'll be back.

  20. #20

    Thread Starter
    Addicted Member Golfreak's Avatar
    Join Date
    Oct 2005
    Location
    stuck in a cube
    Posts
    147

    Re: [RESOLVED] 'System.Data.SqlClient.SqlException'

    Oooooooh NOOOOOOO!!!!

    I spoke too soon! Now I'm getting the error in a different sub on the same form.

    The error:

    VB Code:
    1. An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll
    2.  
    3. Additional information: System error.

    is back.

    The Code:

    VB Code:
    1. Public Sub cmdAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAdd.Click
    2.  
    3.         If txtNew.Text <> "" Then
    4.  
    5.            SqlInsertCommand1.CommandText = "ProblemCategoryAdd '" & txtNew.Text & "'"
    6.             SqlInsertCommand1.CommandType = CommandType.StoredProcedure
    7.             SqlInsertCommand1.Parameters.Clear()
    8.             [B]SqlInsertCommand1.ExecuteReader()[/B]
    9.             txtNew.Text = ""
    10.             txtNew.Select()
    11.         End If
    12.  
    13.         UpdateCombo()
    14.  
    15. End Sub

    is different.

    What did I screw up now???

  21. #21
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: [RESOLVED] 'System.Data.SqlClient.SqlException'

    Sigh....
    Ok.... time for some ADO.NET 100.

    There are several ways to execute SQL statements.
    .ExecuteNonQuery - this is for when you want to do something like a Delete or an Update or even an Insert, or any statement where no data will be returned to the application.
    .ExecuteReader - this does return records, but put it into an efficient forward only, read only stream. One record at a time.
    .Execute - standard, normal execute method. Returns a recordset (datatable) that can then be manipulated.

    So, based on that, can you determine what method you should be using to execute your statement there?

    -----
    Next.
    I'm going to tell you right now, this is the worst way to execute stored procedures:
    SqlInsertCommand1.CommandText = "ProblemCategoryAdd '" & txtNew.Text & "'"

    It opens you to what is known as SQL Injection, where someone can manipulate your database by modifying what's in the text box.

    VB Code:
    1. SqlInsertCommand1.CommandText = "ProblemCategoryAdd"
    2. SqlInsertCommand1.CommandType = CommandType.StoredProcedure
    3. SqlInsertCommand1.Parameters.Clear()
    4. SqlInsertCommand1.Parameters.Add (new SqlClient.SqlParameter("@MyParam", SqlDbType.VarChar, 50)
    5. SqlInsertCommand1.Parameters("@MyParam").Value = txtNew.Text

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  22. #22

    Thread Starter
    Addicted Member Golfreak's Avatar
    Join Date
    Oct 2005
    Location
    stuck in a cube
    Posts
    147

    Re: [RESOLVED] 'System.Data.SqlClient.SqlException'

    I once again thank you techgnome for your help.

    Now my form is almost complete (or should I say your form )

    I can add a name to my DB w/ the form, but I can't delete it

    I am getting the same Error message in my cmdDelete Sub

    This is my code:

    VB Code:
    1. Public Sub cmdDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDelete.Click
    2.  
    3.         If cmbSelect.SelectedIndex <> -1 Then
    4.  
    5.             SqlDeleteCommand1.CommandText = "ProblemCategoryDelete" & cmbSelect.Text & "'"
    6.             SqlDeleteCommand1.CommandType = CommandType.StoredProcedure
    7.             SqlDeleteCommand1.Parameters.Clear()
    8.             SqlDeleteCommand1.ExecuteNonQuery()
    9.             cmbSelect.Select()
    10.  
    11.         End If
    12.  
    13.         UpdateCombo()
    14.  
    15.     End Sub

    I have been playing with the code for about an hour or so and I know its close but its still not right

    Any suggestions??

  23. #23

    Thread Starter
    Addicted Member Golfreak's Avatar
    Join Date
    Oct 2005
    Location
    stuck in a cube
    Posts
    147

    Re: [RESOLVED] 'System.Data.SqlClient.SqlException'

    Anyone????

  24. #24
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: [RESOLVED] 'System.Data.SqlClient.SqlException'

    You're missing a space after your stored proc name:
    "ProblemCategoryDelete" & cmbSelect.Text & "'"

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  25. #25

    Thread Starter
    Addicted Member Golfreak's Avatar
    Join Date
    Oct 2005
    Location
    stuck in a cube
    Posts
    147

    Re: [RESOLVED] 'System.Data.SqlClient.SqlException'

    Actually the error
    VB Code:
    1. An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll
    2.  
    3. Additional information: System error.

    is bolded:
    VB Code:
    1. Public Sub cmdDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDelete.Click
    2.  
    3.         If cmbSelect.SelectedIndex <> -1 Then
    4.  
    5.             SqlDeleteCommand1.CommandText = "ProblemCategoryDelete" & cmbSelect.Text & "'"
    6.             SqlDeleteCommand1.CommandType = CommandType.StoredProcedure
    7.             SqlDeleteCommand1.Parameters.Clear()
    8.             [B]SqlDeleteCommand1.ExecuteNonQuery()[/B]
    9.             cmbSelect.Select()
    10.  
    11.         End If
    12.  
    13.         UpdateCombo()
    14.  
    15.     End Sub

  26. #26
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: [RESOLVED] 'System.Data.SqlClient.SqlException'

    Quote Originally Posted by techgnome
    You're missing a space after your stored proc name:
    "ProblemCategoryDelete" & cmbSelect.Text & "'"

    -tg
    The answer is bolded.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  27. #27

    Thread Starter
    Addicted Member Golfreak's Avatar
    Join Date
    Oct 2005
    Location
    stuck in a cube
    Posts
    147

    Re: [RESOLVED] 'System.Data.SqlClient.SqlException'

    I am not sure what you mean.........

    Are you saying make it look like this?

    VB Code:
    1. SqlDeleteCommand1.CommandText = "ProblemCategoryDelete " & cmbSelect.Text & "'"

  28. #28

    Thread Starter
    Addicted Member Golfreak's Avatar
    Join Date
    Oct 2005
    Location
    stuck in a cube
    Posts
    147

    Re: [RESOLVED] 'System.Data.SqlClient.SqlException'

    Because I tried that and got the same error message

  29. #29

    Thread Starter
    Addicted Member Golfreak's Avatar
    Join Date
    Oct 2005
    Location
    stuck in a cube
    Posts
    147

    Re:'System.Data.SqlClient.SqlException'

    When I run the program it iniciates the form.

    I can add a name to the DB, but when I try to delete a name from the drop down, it throughs the error.

    I am open for suggestions from anyone

  30. #30
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: [RESOLVED] 'System.Data.SqlClient.SqlException'

    Yes, that's exactly what I meant. The fact that you still get an error though means there is something else wrong.

    Try wrapping your executenonquery into a Try...Catch block and trap for the sql error and display it.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  31. #31
    Frenzied Member Asgorath's Avatar
    Join Date
    Sep 2004
    Location
    Saturn
    Posts
    2,036

    Re: [RESOLVED] 'System.Data.SqlClient.SqlException'

    You need to pass the apropriate parameter of your stored procedure ProblemCategoryDelete ...
    VB Code:
    1. Public Sub cmdDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDelete.Click
    2.  
    3.         If cmbSelect.SelectedIndex <> -1 Then
    4.  
    5.             SqlDeleteCommand1.CommandText = "ProblemCategoryDelete"  
    6.             SqlDeleteCommand1.CommandType = CommandType.StoredProcedure
    7.             SqlDeleteCommand1.Parameters.Clear()
    8. SqlDeleteCommand1.Parameters.Add("@YourStoredProcedureParameterPassed",SqlDbType.VarChar).Value = cmbSelect.Text
    9.             SqlDeleteCommand1.ExecuteNonQuery()
    10.             cmbSelect.Select()
    11.  
    12.         End If
    13.  
    14.         UpdateCombo()
    15.  
    16.     End Sub

    Regards
    Jorge
    "The dark side clouds everything. Impossible to see the future is."

  32. #32

    Thread Starter
    Addicted Member Golfreak's Avatar
    Join Date
    Oct 2005
    Location
    stuck in a cube
    Posts
    147

    Re: [RESOLVED] 'System.Data.SqlClient.SqlException'

    Thanks again tg. I'll give it a try

  33. #33

    Thread Starter
    Addicted Member Golfreak's Avatar
    Join Date
    Oct 2005
    Location
    stuck in a cube
    Posts
    147

    Re: [RESOLVED] 'System.Data.SqlClient.SqlException'

    thanks Asgorath, but would you use SqlDeleteCommand1.Parameters.Add() in that situation?

  34. #34
    Frenzied Member Asgorath's Avatar
    Join Date
    Sep 2004
    Location
    Saturn
    Posts
    2,036

    Re: [RESOLVED] 'System.Data.SqlClient.SqlException'

    yes you have to add the parameter your stored procedure , post your ProblemCategoryDelete code....
    "The dark side clouds everything. Impossible to see the future is."

  35. #35

    Thread Starter
    Addicted Member Golfreak's Avatar
    Join Date
    Oct 2005
    Location
    stuck in a cube
    Posts
    147

    Re: [RESOLVED] 'System.Data.SqlClient.SqlException'

    This is the code:

    VB Code:
    1. Public Sub cmdDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDelete.Click
    2.  
    3.         If cmbSelect.SelectedIndex <> -1 Then
    4.  
    5.             SqlDeleteCommand1.CommandText = "ProblemCategoryDelete " & cmbSelect.Text & "'"
    6.             SqlDeleteCommand1.CommandType = CommandType.StoredProcedure
    7.             SqlDeleteCommand1.Parameters.Clear()
    8.             SqlDeleteCommand1.Parameters.Add("@ProblemCategory", SqlDbType.VarChar).Value = cmbSelect.Text
    9.             SqlDeleteCommand1.ExecuteNonQuery()
    10.             cmbSelect.Select()
    11.  
    12.         End If
    13.  
    14.         UpdateCombo()
    15.  
    16.     End Sub

    This is the error:

    VB Code:
    1. An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll
    2.  
    3. Additional information: System error.

  36. #36
    Frenzied Member Asgorath's Avatar
    Join Date
    Sep 2004
    Location
    Saturn
    Posts
    2,036

    Re: [RESOLVED] 'System.Data.SqlClient.SqlException'

    try this ... the .commantText is just the name of stored procedure only....
    VB Code:
    1. Public Sub cmdDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDelete.Click
    2.  
    3.         If cmbSelect.SelectedIndex <> -1 Then
    4.  
    5.             SqlDeleteCommand1.CommandText = "ProblemCategoryDelete"
    6.             SqlDeleteCommand1.CommandType = CommandType.StoredProcedure
    7.             SqlDeleteCommand1.Parameters.Clear()
    8.             SqlDeleteCommand1.Parameters.Add("@ProblemCategory", SqlDbType.VarChar).Value = cmbSelect.Text
    9.             SqlDeleteCommand1.ExecuteNonQuery()
    10.             cmbSelect.Select()
    11.  
    12.         End If
    13.  
    14.         UpdateCombo()
    15.  
    16.     End Sub
    "The dark side clouds everything. Impossible to see the future is."

  37. #37

    Thread Starter
    Addicted Member Golfreak's Avatar
    Join Date
    Oct 2005
    Location
    stuck in a cube
    Posts
    147

    Re: [RESOLVED] 'System.Data.SqlClient.SqlException'

    Thanks Asgorath

    That did the trick

  38. #38
    Frenzied Member Asgorath's Avatar
    Join Date
    Sep 2004
    Location
    Saturn
    Posts
    2,036

    Re: [RESOLVED] 'System.Data.SqlClient.SqlException'

    well finally
    "The dark side clouds everything. Impossible to see the future is."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width