0

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 .

3
Contributors
11
Replies
13
Views
10 Years
Discussion Span
Last Post by arjunsasidharan
0

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

0

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

0

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

0

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.

0

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

0

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."

0

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?

0

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 "

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.