0

A very simple issue im having trying to return a dataset from a VB.NET object function.

The following shows my function that is currently exiting from the function as soon as the SQL query is run and just before the new object connection is created.

The edit form is called here:

 edit.Show()

Within the edit form, the following is run to to retrieve the details of the selected data in the database fro a retrieved datatset of the 'editEntry' method based on the ID set at the constructor.

 Private Sub edit_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


    Dim editDetails As New DBHandler(ID)

    Dim returnedDetails As New DataSet

    returnedDetails = editDetails.editEntry()

    Dim nameReturned As Object = returnedDetails.Tables("editedTable").Rows(0)(1)

    Dim firstNameEdit As String = nameReturned.ToString()

    TextBox1.Text = firstNameEdit

This is the function where the problem is occuring. Nothing is being returned from the query

Constructor where the ID is set:

 Public Sub New(ByVal ID As Integer)

    IDofFault = ID

End Sub

The function of the class:

Public Function editEntry() As DataSet

    Dim editDataSet As New DataSet
    Dim editSql As String = "SELECT * FROM duraGadget WHERE _id = " + IDofFault + ""

    'Exiting from the function here
    Dim connectionEdit As New OleDbConnection(conString)
    Dim editAdapter As New OleDbDataAdapter(editSql, connectionEdit)

    connectionEdit.Open()

    editAdapter.Fill(editDataSet, "editedTable")

    connectionEdit.Close()

    Return editDataSet

End Function

There is no error it simply exits from the function and im not sure why.

user1352057
  • 3,162
  • 9
  • 51
  • 117
  • 1
    Where is `IDofFault` set? – Rowland Shaw May 31 '13 at 15:59
  • It is passed from a cell click method to the constructor of the DBHandler class when the instance of 'editDetails' is made. I have check this in debug and the correct ID is being passed and set. – user1352057 May 31 '13 at 16:00
  • The technique you used to include IDofFault in the query is subject to sql injection. It's okay here because it's an integer variable, but if you do that elsewhere you're extremely vulnerable. It's practially begging to get hacked. – Joel Coehoorn May 31 '13 at 16:09
  • Related: http://stackoverflow.com/a/4002709/3043 – Joel Coehoorn May 31 '13 at 16:12
  • possible duplicate of [VS2010 does not show unhandled exception message in a WinForms Application on a 64-bit version of Windows](http://stackoverflow.com/questions/4933958/vs2010-does-not-show-unhandled-exception-message-in-a-winforms-application-on-a) – Hans Passant May 31 '13 at 16:21

2 Answers2

2

You could be receiving an exception and your visual studio debug settings are not configured to stop you on those types of exceptions.

Wrap the contents of the EditEntry function in a Try / Catch block, and put a break point inside the catch. See if that triggers and look at the exception details for more info on what occurred.

David C
  • 3,610
  • 3
  • 21
  • 23
  • That wont trigger as the code is exiting just after the SQL and just before the connection object is beeing created. – user1352057 May 31 '13 at 16:06
  • 1
    @user1352057 Not before: **during**. The act of creating the connection throws the exception, and VS is ignoring that exception it shows in the debugger like the line never runs. – Joel Coehoorn May 31 '13 at 16:11
1

Very silly error this was guys. I simply stored the ID value as a sting...then tried to pass it as an Integer to the constructor...the result?.....Conversion exception.

user1352057
  • 3,162
  • 9
  • 51
  • 117
  • And to add....being a mainly c# dev, the use of the '+' simply to add my variable to equation was causing it to be seen as a equation. For anyone who reads this and runs into the same issue please use '&' instead of '+' to concatenate your SQL query! – user1352057 May 31 '13 at 16:43
  • This is why it is good practice to add Option Strict On to the top of your code or set it in the project's properties. You would have immediately gotten a compile error. – Chris Dunaway Jun 03 '13 at 14:50