Hi
I am trying to create a stored procedure for retrieving data from tables. Code is
Public Sub SelectData()
dim table,OPtable as string
SqlQuery = "Select * from " & table & ""
Sqlcommand = New MySqlCommand(SqlQuery, Conn)
count = Sqlcommand.ExecuteScalar
Dim Da As New MySqlDataAdapter
Dim Ds As New DataSet
Da.SelectCommand = Sqlcommand
Da.Fill(Ds, OPtable)
MessageBox.Show(Ds.Tables(OPtable).Rows(0)("Name")) -- All OK till here
End Sub
now when i call above procedure with following code
Private Sub BtnFirst_Click_1(sender As Object, e As EventArgs) Handles BtnFirst.Click
table = "Ledgers"
OPtable = "LEDG"
Try
SelectData()
TxtName.Text = Ds.Tables("LEDG").Rows(2)("Name") // error occurs here
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
error is object reference not set to instance of an object
What I have tried:
when I copy code in stored procedure to button click event everything works fine.
I am trying to move records (first, last, next, previous). I was thinking of collecting records from a table into Dataset(Ds) and then move it as required. Is there any simpler way to do this?