943,907 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 6434
  • VB.NET RSS
You are currently viewing page 1 of this multi-page discussion thread
May 4th, 2008
0

creating next and previous button?

Expand Post »
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")
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
gabanxx is offline Offline
30 posts
since Apr 2008
May 5th, 2008
0

Re: creating next and previous button?

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

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(0).Item("Date_of_birth")

Quote ...
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
VB.NET Syntax (Toggle Plain Text)
  1. TextBox1.Text = varDataSet.Tables("tbl_rop").Rows(Record_num).Item("Name_user")
  2. .....
Last edited by manal; May 5th, 2008 at 3:39 am.
Reputation Points: 37
Solved Threads: 17
Junior Poster
manal is offline Offline
122 posts
since Mar 2006
May 5th, 2008
0

Re: creating next and previous button?

how to declare global variable?
Reputation Points: 10
Solved Threads: 0
Light Poster
gabanxx is offline Offline
30 posts
since Apr 2008
May 5th, 2008
0

Re: creating next and previous button?

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?
Last edited by gabanxx; May 5th, 2008 at 5:25 am.
Reputation Points: 10
Solved Threads: 0
Light Poster
gabanxx is offline Offline
30 posts
since Apr 2008
May 5th, 2008
0

Re: creating next and previous button?

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

VB.NET Syntax (Toggle Plain Text)
  1. public class form1
  2. dim Record_num as integer=0

other thing , you must check if that Record_num is not last record
VB.NET Syntax (Toggle Plain Text)
  1. If Record_num <> Number_of_Rows - 1 Then
  2. Record_num = +1
  3. TextBox1.Text = varDataSet.Tables(0).Rows(Record_num).Item("Name_User")
  4. TextBox2.Text = varDataSet.Tables(0).Rows(Record_num).Item("Date_of_birth")
  5. TextBox3.Text = varDataSet.Tables(0).Rows(Record_num).Item("Hobbies")
  6. TextBox4.Text = varDataSet.Tables(0).Rows(Record_num).Item("Phone_number")
Last edited by manal; May 5th, 2008 at 6:16 am.
Reputation Points: 37
Solved Threads: 17
Junior Poster
manal is offline Offline
122 posts
since Mar 2006
May 5th, 2008
0

Re: creating next and previous button?

do i need to declare the Number_of_Rows?
Reputation Points: 10
Solved Threads: 0
Light Poster
gabanxx is offline Offline
30 posts
since Apr 2008
May 5th, 2008
0

Re: creating next and previous button?

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
Reputation Points: 10
Solved Threads: 0
Light Poster
gabanxx is offline Offline
30 posts
since Apr 2008
May 5th, 2008
1

Re: creating next and previous button?

is it solved ? or you still have problem

Quote ...
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
Last edited by manal; May 5th, 2008 at 7:00 am.
Reputation Points: 37
Solved Threads: 17
Junior Poster
manal is offline Offline
122 posts
since Mar 2006
May 5th, 2008
0

Re: creating next and previous button?

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..
Last edited by gabanxx; May 5th, 2008 at 11:02 pm.
Reputation Points: 10
Solved Threads: 0
Light Poster
gabanxx is offline Offline
30 posts
since Apr 2008
May 5th, 2008
0

Re: creating next and previous button?

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
Reputation Points: 10
Solved Threads: 0
Light Poster
gabanxx is offline Offline
30 posts
since Apr 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: User Controls as Forms within a Form
Next Thread in VB.NET Forum Timeline: Help with deleting records from text file





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC