creating next and previous button?

Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Apr 2008
Posts: 30
Reputation: gabanxx is an unknown quantity at this point 
Solved Threads: 0
gabanxx gabanxx is offline Offline
Light Poster

creating next and previous button?

 
0
  #1
May 4th, 2008
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")
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 121
Reputation: manal is an unknown quantity at this point 
Solved Threads: 17
manal's Avatar
manal manal is offline Offline
Junior Poster

Re: creating next and previous button?

 
0
  #2
May 5th, 2008
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")

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
  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.
"give only what u willing to receive "
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 30
Reputation: gabanxx is an unknown quantity at this point 
Solved Threads: 0
gabanxx gabanxx is offline Offline
Light Poster

Re: creating next and previous button?

 
0
  #3
May 5th, 2008
how to declare global variable?
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 30
Reputation: gabanxx is an unknown quantity at this point 
Solved Threads: 0
gabanxx gabanxx is offline Offline
Light Poster

Re: creating next and previous button?

 
0
  #4
May 5th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 121
Reputation: manal is an unknown quantity at this point 
Solved Threads: 17
manal's Avatar
manal manal is offline Offline
Junior Poster

Re: creating next and previous button?

 
0
  #5
May 5th, 2008
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

  1. public class form1
  2. dim Record_num as integer=0

other thing , you must check if that Record_num is not last record
  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.
"give only what u willing to receive "
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 30
Reputation: gabanxx is an unknown quantity at this point 
Solved Threads: 0
gabanxx gabanxx is offline Offline
Light Poster

Re: creating next and previous button?

 
0
  #6
May 5th, 2008
do i need to declare the Number_of_Rows?
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 30
Reputation: gabanxx is an unknown quantity at this point 
Solved Threads: 0
gabanxx gabanxx is offline Offline
Light Poster

Re: creating next and previous button?

 
0
  #7
May 5th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 121
Reputation: manal is an unknown quantity at this point 
Solved Threads: 17
manal's Avatar
manal manal is offline Offline
Junior Poster

Re: creating next and previous button?

 
1
  #8
May 5th, 2008
is it solved ? or you still have problem

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.
"give only what u willing to receive "
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 30
Reputation: gabanxx is an unknown quantity at this point 
Solved Threads: 0
gabanxx gabanxx is offline Offline
Light Poster

Re: creating next and previous button?

 
0
  #9
May 5th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 30
Reputation: gabanxx is an unknown quantity at this point 
Solved Threads: 0
gabanxx gabanxx is offline Offline
Light Poster

Re: creating next and previous button?

 
0
  #10
May 5th, 2008
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
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC