Dim conn As New SqlConnection(connstr1)
Dim sql As String
sql = "Select * from address1"
'Dim da As SqlDataAdapter
Dim cmd As New SqlCommand(sql, conn)
conn.Open()
Dim ds As New DataSet()
da = New SqlDataAdapter(sql, conn)
da.Fill(ds, "Address1")
maxrows = ds.Tables("Address1").Rows.Count
inc = -1
conn.Close()
'If next_record <= maxrows - 1 Then

If inc <> maxrows - 1 Then
inc = inc + 1
'NavigateRecords()
TextBox1.Text = ds.Tables("address1").Rows(inc).Item("rollno").ToString
TextBox2.Text = ds.Tables("address1").Rows(inc).Item("name").ToString
'inc = inc + 1
End If


I am new in vb.net .
I want next record when i Click on Next button Each time .
I am using Vb.net & sql server 2005 as a back end .
please help me .

Recommended Answers

All 11 Replies

Hi,

Code is all OK, Open the Connection In FormLoad. and Write the Population of textbox in CmdNext_Click event..
Declare all the Variables FormLevel.

REgards
Veena

Hi,

Code is all OK, Open the Connection In FormLoad. and Write the Population of textbox in CmdNext_Click event..
Declare all the Variables FormLevel.

REgards
Veena

I have done as per your suggestion .
But it Gives error as follows "Object reference not set to an instance of an object."

Changed code is as
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'Dim conn As New SqlConnection(connstr1)
'Dim sql As String
'sql = "Select * from address1"
'Dim da As SqlDataAdapter
'Dim cmd As New SqlCommand(sql, conn)
'conn.Open()
'Dim ds As New DataSet()
'da = New SqlDataAdapter(sql, conn)
'da.Fill(ds, "Address1")
'maxrows = ds.Tables("Address1").Rows.Count
'inc = -1
'conn.Close()
'If next_record <= maxrows - 1 Then

If inc <> maxrows - 1 Then
inc = inc + 1
'NavigateRecords()
TextBox1.Text = ds.Tables("address1").Rows(inc).Item("rollno").ToString
TextBox2.Text = ds.Tables("address1").Rows(inc).Item("name").ToString
'inc = inc + 1
End If

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'conn.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\AddressBook.mdb"
connstr1 = "server=kishorjagtap;uid=sa;pwd=kishor;database=addressbook"
Dim conn As New SqlConnection(connstr1)
Dim sql As String
sql = "Select * from address1"
Dim cmd As New SqlCommand(sql, conn)
conn.Open()
Dim ds As New DataSet()
da = New SqlDataAdapter(sql, conn)
da.Fill(ds, "Address1")
maxrows = ds.Tables("Address1").Rows.Count
inc = -1
conn.Close()
End Sub

Hi,

Code is all OK, Open the Connection In FormLoad. and Write the Population of textbox in CmdNext_Click event..
Declare all the Variables FormLevel.

REgards
Veena

I have done as per your suggestion .
But it Gives error as follows "Object reference not set to an instance of an object."

Changed code is as
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'Dim conn As New SqlConnection(connstr1)
'Dim sql As String
'sql = "Select * from address1"
'Dim da As SqlDataAdapter
'Dim cmd As New SqlCommand(sql, conn)
'conn.Open()
'Dim ds As New DataSet()
'da = New SqlDataAdapter(sql, conn)
'da.Fill(ds, "Address1")
'maxrows = ds.Tables("Address1").Rows.Count
'inc = -1
'conn.Close()
'If next_record <= maxrows - 1 Then

If inc <> maxrows - 1 Then
inc = inc + 1
'NavigateRecords()
TextBox1.Text = ds.Tables("address1").Rows(inc).Item("rollno").ToString
TextBox2.Text = ds.Tables("address1").Rows(inc).Item("name").ToString
'inc = inc + 1
End If

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'conn.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\AddressBook.mdb"
connstr1 = "server=kishorjagtap;uid=sa;pwd=kishor;database=addressbook"
Dim conn As New SqlConnection(connstr1)
Dim sql As String
sql = "Select * from address1"
Dim cmd As New SqlCommand(sql, conn)
conn.Open()
Dim ds As New DataSet()
da = New SqlDataAdapter(sql, conn)
da.Fill(ds, "Address1")
maxrows = ds.Tables("Address1").Rows.Count
inc = -1
conn.Close()
End Sub

Hi,

what line u r getting the error...?


Regards
Veena

Why don't you insert some break points and cycle through your code using F10 or F11 and tell us which part your getting the error.

hello,

as i said, declare all teh variables
Form-LEVEL

Means on the top of form.. u have declared in Page Load...
and Put the inc=inc+1 outside the if Condition

REgards
Veena

I have done it it shows error when i Press Button Click . At the time the records we want to display on text box it gives Error as " Object reference not set to an instance of an object."

what did you declare inc as? Did you try my suggestion as which line your getting the error?.

Show us which part of the line your getting error?

Try using the databindings in the textbox

Textbox1.DataBindings.Add("Text", ds.Address1, "rollno")

Try using the databindings in the textbox

Textbox1.DataBindings.Add("Text", ds.Address1, "rollno")

after doing this it shows messages
"address1 is not the member of system.data.dataset "

after doing this it shows messages
"address1 is not the member of system.data.dataset "

sorry that wouldn't have worked

Well i can only give you suggestions

Try retrieveing the data in a Sqldatareader

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'conn.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\AddressBook.mdb"
connstr1 = "server=kishorjagtap;uid=sa;pwd=kishor;database=addressbook"
Dim conn As New SqlConnection(connstr1)
Dim sql As String
sql = "Select * from address1"
conn.Open()
Dim cmd As New SqlCommand(sql, conn)
dim drSql as SqlDataReader
drsql = cmd.ExecuteReader
If drSql.Read() then
TextBox1.Text = drSql.Item("rollno").ToString()
TextBox2.Text = drSql.Item("name").ToString()
End IF

Dim ds As New DataSet()
da = New SqlDataAdapter(sql, conn)
da.Fill(ds, "Address1")
maxrows = ds.Tables("Address1").Rows.Count
inc = -1
conn.Close()
End Sub

Don't know whether it will work.. Just try it out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.