Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > ds.Tables returns no rows
 

ds.Tables returns no rows

I have a project where I am running a list of stored procedures using SqlDataAdapter and updating a listview with the results.Everyproceduretakes a part number and customer name as parameters and returns @BOM(build of material), @Description, and @QTY. I have two customers the 1st everything works fine each stored proceedure preduces data as it should but the second customer does everything correctly until it gets to a certin stored proceedure and I get an error saying there is no row at position 0. Executing this stored procedure within the database I get three rows of data but from within the program I get nothing. When I submit my 1st customer into the same stored procudre I get 3 rows of data both from within the program and from running it in sql server. I have been up till 11pm at work trying to figure this out and I am stuck. Here is my code and If anyone would be so kind as to do a team viewer session with me to troubleshoot email me at mike_coleman_lte@yahoo.com

1st my program executes a stored procedure that gets a list of stored procedures to call from a table. Loops through that table and calls a function to execute each procedure and fills a dataset with the results.

Private

Sub cmdGetBoms_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGetBoms.Click

Dim SP As String

If ListView1.Items.Count > 0 Then

ListView1.Items.Clear()

End If

Try

Dim ds = ExecuteDataSet("GET_SPLIST", CommandType.StoredProcedure)

For I As Integer = 0 To ds.Tables(0).Rows.Count - 1

Try

SP = Trim(ds.Tables(0).Rows(I)(0).ToString)

ExecuteProc(SP)

Catch ex As ApplicationException

MsgBox(

"Error" & vbCrLf & ex.Message)

End Try

Next

Catch ex As ApplicationException

End Try
end sub

Here is the code for ExecuteProc

Private

Sub ExecuteProc(ByVal ProcName As String)

Dim helper As New ParmHelper

'helper.AddParm("@PartNumber", GetAllPartNumbers, SqlDbType.NChar, 50)

'helper.AddParm("@CustomerName", CustomerName.Trim(" "), SqlDbType.NChar, 100)

helper.AddParm(

"@CustomerName", "carrier 62e", SqlDbType.NChar, 100)

helper.AddParm(

"@PartNumber", "CCCC--XR61-ra", SqlDbType.NChar, 50)

Dim ds = ExecuteDataSet(ProcName, CommandType.StoredProcedure, helper.GetAllParm)

Try

Dim Qty As String = ""

Dim Desc As String = ""

Dim Boms As String = ""

If ds.Tables.Count = 1 Then 'my program gets this far sees a 1 table

Debug.Print(ds.Tables(0).Rows.Count) 'however this returns zero rows

Debug.Print(ds.Tables(0).Rows(0)(0).ToString)

Debug.Print(CustomerName)

For I As Integer = 0 To ds.Tables(0).Rows.Count - 1

Boms = ds.Tables(0).Rows(I)(0).ToString

Desc = ds.Tables(0).Rows(I)(1).ToString

Qty = ds.Tables(0).Rows(I)(2).ToString

Dim lstItm As ListViewItem = ListView1.Items.Add(Qty)

lstItm.SubItems.Add(Boms)

lstItm.SubItems.Add(Desc)

Next

Else

If (ds.Tables(0).Rows.Count > 0) Then

Boms = ds.Tables(0).Rows(0)(0).ToString

End If

If (ds.Tables(1).Rows.Count > 0) Then

Desc = ds.Tables(1).Rows(0)(0).ToString

End If

If (ds.Tables(2).Rows.Count > 0) Then

Qty = ds.Tables(2).Rows(0)(0).ToString

End If

'Dim lstItm As ListViewItem =

Dim lstItm As ListViewItem = ListView1.Items.Add(Qty)

lstItm.SubItems.Add(Boms)

lstItm.SubItems.Add(Desc)

End If

Catch Ex As Exception

Debug.Print(

"Error" & vbCrLf & Ex.Message)

MsgBox(

"Error" & vbCrLf & Ex.Message)

End Try

End Sub



Here is my code for ExecuteDataSet


Public

Function ExecuteDataSet(ByVal Sql As String, ByVal SqlCmdType As CommandType) As DataSet

Return ExecuteDataSet(Sql, SqlCmdType, Nothing)

End Function

Public Function ExecuteDataSet(ByVal Sql As String, ByVal SqlCmdType As CommandType, ByVal Parms As List(Of SqlParameter)) As DataSet

Dim con As SqlConnection = GetConnection()

Dim cmd As New SqlCommand(Sql, con)

cmd.CommandType = SqlCmdType

LoadParms(cmd, Parms)

Try

Dim Sda As New SqlDataAdapter(cmd)'both command and connection look good.

Dim ds As New DataSet

Sda.Fill(ds)'program seems to do this step twice not sure what that means.

Return ds

Catch ex As Exception

MsgBox(ex.Message)

End Try

Return Nothing

End Function






mike coleman  Saturday, August 15, 2009 12:56 PM
Hello...

Without looking at the back end its hard to say anything about your problem,,,

The problem may be in the SPs or the Data stored in the Tables...

Please check for it first or mail it in details at rajxm_421@hotmail.com.

I will check the same...

Regards,,,,,

Nothing is Impossible.....
R.KUMAR  Thursday, August 20, 2009 1:18 PM

We are changing the issue type to “General Discussion�because you have not followed up with the necessary information. If you have more time to look at the issue and provide more information, please feel free to change the issue type back to “Question�by opening the Options list at the top of the post window, and changing the type. If the issue is resolved, we will appreciate it if you can share the solution so that the answer can be found and used by other community members having similar questions.

Best regards,
Ling Wang


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Monday, August 24, 2009 2:30 AM

You can use google to search for other answers

Custom Search

More Threads

• Combo Box Error - DataGridViewComboBoxCell value is not valid
• C# connection to Access Database
• datagrid check
• cm.Position won't leave Zero
• Multiple combobox bindings
• i have a question
• Typed DataSet with Oracle
• Simple databinding question - newbie
• Saving to SQL Server Data Base
• Custom Control and DataBinding