Hi
I'm trying to retreive data into textbox using Sql database.
the error points at "tb2.Text = ds.Tables[0].Rows[r].ItemArray[0].ToString()" and "if rowindex == (ds.Tables[0].Rows.Count - 1) then" while I'm trying to view the next record(data row) in the data table and the error is "Object reference not set to an instance of an object".
I have created an Userdefined Method as "RecordDisplay(int r)" where 'r' is the row index.
Where I could be wrong?
vanisri
I'm trying to retreive data into textbox using Sql database.
the error points at "tb2.Text = ds.Tables[0].Rows[r].ItemArray[0].ToString()" and "if rowindex == (ds.Tables[0].Rows.Count - 1) then" while I'm trying to view the next record(data row) in the data table and the error is "Object reference not set to an instance of an object".
I have created an Userdefined Method as "RecordDisplay(int r)" where 'r' is the row index.
Where I could be wrong?
vanisri
VB.NET:
Sub RecordDisplay(ByVal r As Integer)
tb2.Text = ds.Tables(0).Rows(r).ItemArray(0).ToString()
tb1.Text = ds.Tables(0).Rows(r).ItemArray(1).ToString()
tb3.Text =ds.Tables(0).Rows(r).ItemArray(2).ToString()
End Sub
Dim rowindex As Integer = 0
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim con As New SqlConnection("Server=(local);DataBase='Northwind';uid='sa'")
Dim adap As New SqlDataAdapter("select * from Phonedetails", con)
Dim ds As New DataSet
adap.Fill(ds, "phonedetails")
dg1.DataSource = ds.Tables("phonedetails")
RecordDisplay(rowindex)
End Sub
'to view the next record
private sub btn_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bt1.Click
If rowindex = ds.Tables(0).Rows.Count - 1 then
bt1.enabled=true
Else
rowindex += 1
RecordDisplay(rowindex)
End If
End Sub