locked
No data exists for the row/column RRS feed

  • Question

  • User-1024202203 posted

    I'm getting a "no data exists for the row/column" error when i am giving wrong value in key column and press button to import data from excel,how can i fix this error and avoid collapsing the application.

        If txtWON.Text <> "" Then
                Try
                    Dim strExcelConn As String = System.Configuration.ConfigurationManager.ConnectionStrings.Item("ExcelConnection").ToString()
                    Dim dbConn As New OleDbConnection(strExcelConn)
                    Dim db As OleDbDataReader
                    Dim strSQL As String
                    strSQL = "SELECT * from [WO$] where Wono=" & txtWON.Text & ""
                    dbConn.Open()
                    Dim cmd As New OleDbCommand(strSQL, dbConn)
                    Dim dsExcel As New DataSet
                    Dim daExcel As New OleDbDataAdapter(cmd)
                    daExcel.Fill(dsExcel)
                    'GVStatus.DataSource = dsExcel
                    'GVStatus.DataBind()
                    db = cmd.ExecuteReader
                    If db.Read() Then
                        Dim rowcount As Integer = 0
                        rowcount = db.GetInt32(0)
                    End If
                    txtWON.Text = db.Item(0).ToString
                    txtPartNumber.Text = db.Item(1).ToString
                    txtRev.Text = db.Item(2).ToString
                    txtOQty.Text = db.Item(3).ToString
                    txtCust.Text = db.Item(4).ToString
                Catch ex As Exception
                    Throw ex
                End Try
            End If


     

    Tuesday, February 1, 2011 8:35 PM

Answers

  • User1218929252 posted

    try this...

    Dim ds as new dataset

    Dim intCount As Integer
    intCount = ds.Tables("myTable").Rows.Count


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 2, 2011 12:54 AM

All replies

  • User1218929252 posted

    try this..

      If txtWON.Text <> "" Then
                Try
                    Dim strExcelConn As String = System.Configuration.ConfigurationManager.ConnectionStrings.Item("ExcelConnection").ToString()
                    Dim dbConn As New OleDbConnection(strExcelConn)
                    Dim db As OleDbDataReader
                    Dim strSQL As String
                    strSQL = "SELECT * from [WO$] where Wono=" & txtWON.Text & ""
                    dbConn.Open()
                    Dim cmd As New OleDbCommand(strSQL, dbConn)
                    Dim dsExcel As New DataSet
                    Dim daExcel As New OleDbDataAdapter(cmd)
                    daExcel.Fill(dsExcel)
                    'GVStatus.DataSource = dsExcel
                    'GVStatus.DataBind()
                    db = cmd.ExecuteReader


                    If db.Read() Then
                        Dim rowcount As Integer = 0
                        rowcount = db.GetInt32(0)

                    txtWON.Text = db.Item(0).ToString
                    txtPartNumber.Text = db.Item(1).ToString
                    txtRev.Text = db.Item(2).ToString
                    txtOQty.Text = db.Item(3).ToString
                    txtCust.Text = db.Item(4).ToString

                    End If

                
                Catch ex As Exception
                    Throw ex
                End Try
            End If

    Wednesday, February 2, 2011 12:02 AM
  • User-1024202203 posted

     I tried it is working fine but when i gave correct value it is throwing exception message "Specified cast is not valid. " after that application collapsed

    Wednesday, February 2, 2011 12:21 AM
  • User1218929252 posted

    this is the code that throws error..

       Dim rowcount As Integer = 0
       rowcount = db.GetInt32(0)

    A reader doesn't have a count. You will need to read all the records and
    keep track of count yourself.

    U can opt Dataset to get the count of rows..

    Wednesday, February 2, 2011 12:42 AM
  • User-1024202203 posted

    Can you please help how can i write it,thanks 

    Wednesday, February 2, 2011 12:46 AM
  • User1218929252 posted

    try this...

    Dim ds as new dataset

    Dim intCount As Integer
    intCount = ds.Tables("myTable").Rows.Count


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 2, 2011 12:54 AM