HELP:IndexOutOfRangeException

Try
Dim GetRetailPrice As New SqlClient.SqlCommand( _
"SELECT RetailPrice FROM ProductDetails WHERE ProductName = '" & _
Me.cmbProductName.Text & "'", New SqlClient.SqlConnection( _
My.Settings.ProjectTanioConnectionString))
Dim GetRetailPriceDataSet As New DataSet()
Dim GetRetailPriceDataAdapter As New SqlClient.SqlDataAdapter(GetRetailPrice)

GetRetailPriceDataAdapter.Fill(GetRetailPriceDataSet)

Dim RetailPrice As Decimal
RetailPrice = GetRetailPriceDataSet.Tables(0).Rows(0).Item(0) '<- there is no row at position 0;
Me.txtRetailPrice.Text = RetailPrice.ToString("N") '-- IndexOutOfRangeException was
'-- unhandled by user code
Catch ex As Exception
System.Windows.Forms.MessageBox.Show(ex.Message)

End Try

the contents of 'GetRetailPriceDataSet.Tables(0).Row(0).Item(0)' seem to disappear
after i inserted a new record to the database after making the selections and
then saving. making a second selection gives me an 'IndexOutOfRangeException'
saying that 'there is no row at position 0'



Answer this question

HELP:IndexOutOfRangeException

  • Ready4u

    perhaps there arent any records in the database

    can you do a check on the number of Tables as well as the number of rows

    Make sure data does exist in the database and also make sure that the query you have, the filter results, do evaluate to true meaning that once you have the WHERE clause for filtering that data is returned/data exists. Currently it could be the fact that there are no results to be returned from your query/search criteria



  • HELP:IndexOutOfRangeException