954,551 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

I want next record to Display

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 .

kishorJagtap
Newbie Poster
6 posts since Aug 2007
Reputation Points: 10
Solved Threads: 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

QVeen72
Posting Shark
950 posts since Nov 2006
Reputation Points: 84
Solved Threads: 143
 
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

kishorJagtap
Newbie Poster
6 posts since Aug 2007
Reputation Points: 10
Solved Threads: 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

kishorJagtap
Newbie Poster
6 posts since Aug 2007
Reputation Points: 10
Solved Threads: 0
 

Hi,

what line u r getting the error...?


Regards
Veena

QVeen72
Posting Shark
950 posts since Nov 2006
Reputation Points: 84
Solved Threads: 143
 

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.

arjunsasidharan
Practically a Posting Shark
826 posts since Aug 2006
Reputation Points: 347
Solved Threads: 13
 

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

QVeen72
Posting Shark
950 posts since Nov 2006
Reputation Points: 84
Solved Threads: 143
 

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

kishorJagtap
Newbie Poster
6 posts since Aug 2007
Reputation Points: 10
Solved Threads: 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?

arjunsasidharan
Practically a Posting Shark
826 posts since Aug 2006
Reputation Points: 347
Solved Threads: 13
 

Try using the databindings in the textbox

Textbox1.DataBindings.Add("Text", ds.Address1, "rollno")
arjunsasidharan
Practically a Posting Shark
826 posts since Aug 2006
Reputation Points: 347
Solved Threads: 13
 

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 "

kishorJagtap
Newbie Poster
6 posts since Aug 2007
Reputation Points: 10
Solved Threads: 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.

arjunsasidharan
Practically a Posting Shark
826 posts since Aug 2006
Reputation Points: 347
Solved Threads: 13
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You