i created a form with 4 textbox tht user can insert their data and stored it in sql server 2000 databse..than i manage to display the data when user starting the program... i also create an update button for user to update their data...
the problem is when i want to move to the next data nothing appear...the same when i want to look for previous data... i really seek help here hope anyone outhere can solve my problem... thakz and appreciate alot

"this the code for button next n previous"

Dim varConnection As New SqlConnection
Dim varDataSet As New DataSet
Dim varAdapter As SqlDataAdapter
Dim varCommand As SqlCommand
Dim varchar As SqlDataAdapter


Dim sql As String


varConnection = New SqlConnection("Server=(local);user id=sa;password=;Initial Catalog=ROP1")

Try
varConnection.Open()
varAdapter.Fill(varDataSet, "tbl_rop")
Dim rowRop1 As System.Data.DataRow

Catch ex As Exception

End Try

sql = "SELECT * FROM tbl_rop"

sql = "SELECT distinct * FROM tbl_rop"
'Dim con As String = ConfigurationSettings.AppSettings("preeconn")
varCommand = New SqlCommand(varQuery, varConnection)

varCommand = New SqlCommand(sql, varConnection)
varAdapter = New SqlDataAdapter(varCommand)
'Dim maxrws As String
Dim i As Integer
varAdapter.Fill(varDataSet)

'sql = varAdapter.Fill(varDataSet)Rows.Count.
'varAdapter.Fill(varDataSet) 'used to get the count of number of rows in a table
i = 0
For i = 0 To -1
TextBox1.Text = varDataSet.Tables("tbl_rop").Rows(0).Item("Name_User")
TextBox2.Text = varDataSet.Tables("tbl_rop").Rows(0).Item("Date_of_birth")
TextBox3.Text = varDataSet.Tables("tbl_rop").Rows(0).Item("Hobbies")
TextBox4.Text = varDataSet.Tables("tbl_rop").Rows(0).Item("Phone_number")

Next i
TextBox1.Text = varDataSet.Tables("tbl_rop").Rows(0).Item("Name_user")
TextBox2.Text = varDataSet.Tables("tbl_rop").Rows(0).Item("Date_of_birth")
TextBox3.Text = varDataSet.Tables("tbl_rop").Rows(0).Item("Hobbies")
TextBox4.Text = varDataSet.Tables("tbl_rop").Rows(0).Item("Phone_number")

i do not understand your code.
>>"this the code for button next n previous" you mean that the same code for next and previous ? each one has its own code

i = 0
[B]For i = 0 To -1[/B]
TextBox1.Text = varDataSet.Tables("tbl_rop").Rows([B]0[/B]).Item("Name_User")
TextBox2.Text = varDataSet.Tables("tbl_rop").Rows(0).Item("Date_of_birth")
TextBox3.Text = varDataSet.Tables("tbl_rop").Rows(0).Item("Hobbies")
TextBox4.Text = varDataSet.Tables("tbl_rop").Rows(0).Item("Phone_number")

Next i
TextBox1.Text = varDataSet.Tables("tbl_rop").Rows(0).Item("Name_user")
TextBox2.Text = varDataSet.Tables("tbl_rop").Rows(0).Item("Date_of_birth")
TextBox3.Text = varDataSet.Tables("tbl_rop").Rows(0).Item("Hobbies")
TextBox4.Text = varDataSet.Tables("tbl_rop").Rows(0).Item("Phone_number")

first why you are using for loop ? and why it is for 0 to -1 ? maybe you mean
for 0 to some_variable-1
any way i do not think you need for loop inside next or previous button
other thing in the code you always display the content of row 0

TextBox2.Text = varDataSet.Tables("tbl_rop").Rows([B]0[/B]).Item("Date_of_birth")

the problem is when i want to move to the next data nothing appear...the same when i want to look for previous data...

i think your code should display the contents of the first row.

any way , the idea is just to keep track for the records
declear global variable for that call it for example Record_num=0
then in next button incremnt it by one and in the previouse button decrease it by one
after that display the record

TextBox1.Text = varDataSet.Tables("tbl_rop").Rows(Record_num).Item("Name_user")
.....

how to declare global variable?

i manage to make the next button work..
but it didnt show all the data just the last data in my database....whats the problem?

this the code for next button..

Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
Dim varConnection As New SqlConnection
Dim varDataSet As New DataSet
Dim varAdapter As SqlDataAdapter
Dim varCommand As SqlCommand
Dim varchar As SqlDataAdapter
Dim Record_num = 0
Dim sql As String


varConnection = New SqlConnection("Server=(local);user id=sa;password=;Initial Catalog=ROP1")


sql = "SELECT * FROM tbl_rop"

sql = "SELECT distinct * FROM tbl_rop"
'Dim con As String = ConfigurationSettings.AppSettings("preeconn")
varCommand = New SqlCommand(varQuery, varConnection)

varCommand = New SqlCommand(sql, varConnection)
varAdapter = New SqlDataAdapter(varCommand)

varAdapter.Fill(varDataSet) 'used to get the count of number of rows in a table
Record_num = +1
TextBox1.Text = varDataSet.Tables(0).Rows(Record_num).Item("Name_User")
TextBox2.Text = varDataSet.Tables(0).Rows(Record_num).Item("Date_of_birth")
TextBox3.Text = varDataSet.Tables(0).Rows(Record_num).Item("Hobbies")
TextBox4.Text = varDataSet.Tables(0).Rows(Record_num).Item("Phone_number")


End Sub

can u help me spot the problem?

the problem that you decleared Record_num inside the next_button code, here each time the user choose next button Record_num will have the same value
define it outside it

public class form1
dim Record_num  as integer=0

other thing , you must check if that Record_num is not last record

If Record_num  <> Number_of_Rows - 1 Then
Record_num = +1
TextBox1.Text = varDataSet.Tables(0).Rows(Record_num).Item("Name_User")
TextBox2.Text = varDataSet.Tables(0).Rows(Record_num).Item("Date_of_birth")
TextBox3.Text = varDataSet.Tables(0).Rows(Record_num).Item("Hobbies")
TextBox4.Text = varDataSet.Tables(0).Rows(Record_num).Item("Phone_number")

do i need to declare the Number_of_Rows?

i have change to code but the problem stiil there ...

Public Class form1
Dim Record_num As Integer = 0
End Class


Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
Dim varConnection As New SqlConnection
Dim varDataSet As New DataSet
Dim varAdapter As SqlDataAdapter
Dim varCommand As SqlCommand
Dim varchar As SqlDataAdapter
Dim sql As String
Dim Record_num = 0
Dim Number_of_Rows As Integer = 0

varConnection = New SqlConnection("Server=(local);user id=sa;password=;Initial Catalog=ROP1")


sql = "SELECT * FROM tbl_rop"

sql = "SELECT distinct * FROM tbl_rop"

varCommand = New SqlCommand(varQuery, varConnection)

varCommand = New SqlCommand(sql, varConnection)
varAdapter = New SqlDataAdapter(varCommand)

varAdapter.Fill(varDataSet) 'used to get the count of number of rows in a table
If Record_num <> Number_of_Rows - 1 Then
Record_num = +1
TextBox1.Text = varDataSet.Tables(0).Rows(Record_num).Item("Name_User")
TextBox2.Text = varDataSet.Tables(0).Rows(Record_num).Item("Date_of_birth")
TextBox3.Text = varDataSet.Tables(0).Rows(Record_num).Item("Hobbies")
TextBox4.Text = varDataSet.Tables(0).Rows(Record_num).Item("Phone_number")


End If

End Sub

is it solved ? or you still have problem :S

Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
Dim varConnection As New SqlConnection
Dim varDataSet As New DataSet
Dim varAdapter As SqlDataAdapter
Dim varCommand As SqlCommand
Dim varchar As SqlDataAdapter
Dim sql As String
Dim Record_num = 0 ' you do not need this here
Dim Number_of_Rows As Integer = 0 'why zero? this will hold number of rows in your table so you will be sure that once you reached last record you will not increment it
varConnection = New SqlConnection("Server=(local);user id=sa;password=;Initial Catalog=ROP1")


sql = "SELECT * FROM tbl_rop"

sql = "SELECT distinct * FROM tbl_rop"

varCommand = New SqlCommand(varQuery, varConnection)

varCommand = New SqlCommand(sql, varConnection)
varAdapter = New SqlDataAdapter(varCommand)

varAdapter.Fill(varDataSet) 'used to get the count of number of rows in a table

Number_of_Rows=varDataSet .Tables("your_table_name").Rows.Count

If Record_num <> Number_of_Rows - 1 Then
Record_num = +1
TextBox1.Text = varDataSet.Tables(0).Rows(Record_num).Item("Name_User")
TextBox2.Text = varDataSet.Tables(0).Rows(Record_num).Item("Date_of_birth")
TextBox3.Text = varDataSet.Tables(0).Rows(Record_num).Item("Hobbies")
TextBox4.Text = varDataSet.Tables(0).Rows(Record_num).Item("Phone_number")


End If

commented: really helpfull +1

it still wont move.. i'have change the code and i cannot remove the Dim Record_num = 0
anything wrong with the

Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
Dim varConnection As New SqlConnection
Dim varDataSet As New DataSet
Dim varAdapter As SqlDataAdapter
Dim varCommand As SqlCommand

Dim sql As String
Dim Record_num = 0'i cannot remove the declaration for record num
Dim Number_of_Rows As Integer =8

varConnection = New SqlConnection("Server=(local);user id=sa;password=;Initial Catalog=ROP1")


sql = "SELECT * FROM tbl_rop"

sql = "SELECT distinct * FROM tbl_rop"

varCommand = New SqlCommand(varQuery, varConnection)

varCommand = New SqlCommand(sql, varConnection)
varAdapter = New SqlDataAdapter(varCommand)


varAdapter.Fill(varDataSet) 'used to get the count of number of rows in a table

Number_of_Rows = varDataSet.Tables("tbl_rop").Rows.Count

If Record_num <> Number_of_Rows - 1 Then
Record_num = +1
TextBox1.Text = varDataSet.Tables(0).Rows(Record_num).Item("Name_User")
TextBox2.Text = varDataSet.Tables(0).Rows(Record_num).Item("Date_of_birth")
TextBox3.Text = varDataSet.Tables(0).Rows(Record_num).Item("Hobbies")
TextBox4.Text = varDataSet.Tables(0).Rows(Record_num).Item("Phone_number")


End If

End Sub


' is there anything that would have been the problem..

here are some changes i made to the code.. as always the problem still the same nothing happen... can you figured it out what seems to be the problem....i really appreciate the help

Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
Dim varConnection As New SqlConnection
Dim varDataSet As New DataSet
Dim varAdapter As SqlDataAdapter
Dim varCommand As SqlCommand

Dim sql As String
Dim Record_num = 0
Dim Number_of_Rows As Integer = 8

varConnection = New SqlConnection("Server=(local);user id=sa;password=;Initial Catalog=ROP1")

varAdapter.Fill(varDataSet) 'used to get the count of number of rows in a table

Number_of_Rows = varDataSet.Tables("tbl_rop").Rows.Count

If Record_num <> Number_of_Rows - 1 Then
Record_num = +1
TextBox1.Text = varDataSet.Tables(0).Rows(Record_num).Item("Name_User")
TextBox2.Text = varDataSet.Tables(0).Rows(Record_num).Item("Date_of_birth")
TextBox3.Text = varDataSet.Tables(0).Rows(Record_num).Item("Hobbies")
TextBox4.Text = varDataSet.Tables(0).Rows(Record_num).Item("Phone_number")


End If

End Sub

here are some changes i made to the code.. as always the problem still the same nothing happen... can you figured it out what seems to be the problem....i really appreciate the help

the problem still the same , you mean it just shows the last record ?

if yes , as I said before initializing Record_num with zero inside the button code is your problem

just imagine what will happen if user press Next button for first time
Record_num = 0 and Number_of_Rows =8
the IF statement will compare two numbers and they not equal and it will enter if statement so ,

Record_num = 1
TextBox1.Text = varDataSet.Tables(0).Rows(1).Item("Name_User")

now what will happen if user press Next for second time ?
actually, the same thing
Record_num = 0 and then Record_num =1
while Record_num should equal to 2

so it will show the same row again

I hope I could explain well this time :S

Dim Record_num = 0'i cannot remove the declaration for record num

why you can not remove it ?
declear it in Form1 class not in button code

the errror i got
An unhandled exception of type 'System.IndexOutOfRangeException' occurred in system.data.dll

Additional information: Cannot find table 0.

i followed all the code.. i have declared
Public Class Form1
Inherits System.Windows.Forms.Form
Dim Record_num As Integer = 0


this is the changes i'have made so far

Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click

Dim varDataSet As New DataSet
Dim Number_of_Rows As Integer = 8


'Record_num = Record_num + 1

If Record_num <> Number_of_Rows + 1 Then
Record_num = 1
TextBox1.Text = varDataSet.Tables(0).Rows(1).Item("Name_User")
TextBox2.Text = varDataSet.Tables(0).Rows(1).Item("Date_of_birth")
TextBox3.Text = varDataSet.Tables(0).Rows(1).Item("Hobbies")
TextBox4.Text = varDataSet.Tables(0).Rows(1).Item("Phone_number")


End If
so why the problem still happen.... hope u can help solve this i really appreciate the help
thaks in advance.......
:confused:

Additional information: Cannot find table 0.
TextBox1.Text = varDataSet.Tables(0).Rows(1).Item("Name_User")

there is no table 0 in your dataset

dim Record_num as integer=0
.
.
Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click

Number_of_Rows = Me.DataSet11.Tables(0).Rows.Count
If Record_num <> Number_of_Rows - 1 Then
Record_num = +1
TextBox1.Text = varDataSet.Tables(0).Rows(Record_num).Item("Name_User")
TextBox2.Text = varDataSet.Tables(0).Rows(Record_num).Item("Date_of_birth")
TextBox3.Text = varDataSet.Tables(0).Rows(Record_num).Item("Hobbies")
TextBox4.Text = varDataSet.Tables(0).Rows(Record_num).Item("Phone_number")
end if

sorry I was mistaken here, Record_num should be initialized with -1 not 0

this time it should really work , just be sure of your dataset that it contains table 0 :S

Dim varConnection As New SqlConnection
Dim varDataSet As New DataSet
Dim varAdapter As SqlDataAdapter
Dim varCommand As SqlCommand
Dim varchar As SqlDataAdapter
Dim sql As String
Dim Number_of_Rows As Integer
varConnection = New SqlConnection("Server=(local);user id=sa;password=;Initial Catalog=ROP1")
sql = "SELECT * FROM tbl_rop"
varCommand = New SqlCommand(sql, varConnection)
varAdapter = New SqlDataAdapter(varCommand)
varAdapter.Fill(varDataSet)

if you removed these lines, return them and see if you still have this problem
:S

"this the code that i have come up with and also the code for previous button.

Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click

Dim Record_num_count As Integer = varDataSet.Tables(0).Rows.Count - 1


If Record_num <> Record_num_count Then
Record_num = Record_num + 1
TextBox1.Text = varDataSet.Tables(0).Rows(Record_num).Item("Name_User")
TextBox2.Text = varDataSet.Tables(0).Rows(Record_num).Item("Date_of_birth")
TextBox3.Text = varDataSet.Tables(0).Rows(Record_num).Item("Hobbies")
TextBox4.Text = varDataSet.Tables(0).Rows(Record_num).Item("Phone_number")

Else
MsgBox("the data has reach it limit")
End If


End Sub


Private Sub btnPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrevious.Click

Dim Record_num_count As Integer = varDataSet.Tables(0).Rows.Count = 1


If Record_num <> Record_num_count Then
Record_num = Record_num - 1
TextBox1.Text = varDataSet.Tables(0).Rows(Record_num).Item("Name_User")
TextBox2.Text = varDataSet.Tables(0).Rows(Record_num).Item("Date_of_birth")
TextBox3.Text = varDataSet.Tables(0).Rows(Record_num).Item("Hobbies")
TextBox4.Text = varDataSet.Tables(0).Rows(Record_num).Item("Phone_number")

Else
MsgBox("Please select the next button")
End If

End Sub

finnally the code work...thknz for the code and time i really appreciate the help
yuo have been a great help to me.......:)

thanx a lot these CODE is working...:)

hi,
I cannot understand.
you are declaring a global variable Row_count and given its value as 0. see i have 4 buttons namely FIRST,NEXT,PREVIOUS and LAST.
in the first button, we are writing like....
[textbox1.text = data.Tables(0).Rows(Row_count).item(0)]
.
.
.
like wise the in the Next button,
[textbox1.text = data.Tables(0).Rows(Row_count + 1).item(0)]
.
.
.
actually it goes to the next record, but it does not move again to next record. can u understand what i'am asking.
like wise for the PREVIOUS also,
actually it searches for the record before '0'. since we are giving like [Rows(Row_count-1)].
can u explain me properly. or can u give me some other coding please?

i have a problem in searching the data either it is existing or not...how to search data from database then display it into field1.text

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.