| | |
creating next and previous button?
Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Apr 2008
Posts: 30
Reputation:
Solved Threads: 0
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")
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
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
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
>>"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...
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)
TextBox1.Text = varDataSet.Tables("tbl_rop").Rows(Record_num).Item("Name_user") .....
Last edited by manal; May 5th, 2008 at 3:39 am.
"give only what u willing to receive "
•
•
Join Date: Apr 2008
Posts: 30
Reputation:
Solved Threads: 0
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?
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.
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
other thing , you must check if that Record_num is not last record
define it outside it
VB.NET Syntax (Toggle Plain Text)
public class form1 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)
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")
Last edited by manal; May 5th, 2008 at 6:16 am.
"give only what u willing to receive "
•
•
Join Date: Apr 2008
Posts: 30
Reputation:
Solved Threads: 0
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
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 

•
•
•
•
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 "
•
•
Join Date: Apr 2008
Posts: 30
Reputation:
Solved Threads: 0
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..
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.
•
•
Join Date: Apr 2008
Posts: 30
Reputation:
Solved Threads: 0
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
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
![]() |
Similar Threads
- Media Player Interface (C#)
- Help with Inventory part 6 program please!! (Java)
- A multilingual coded Hello World! thread (Legacy and Other Languages)
- Problem with java (Java)
- Creating a Robust Logout System (Perl)
- how to go back to previous date (Windows NT / 2000 / XP)
- Text printing is giving me trouble (C#)
- Error Creating Folder message during installation (OS X)
- Help with a Time Keeping Program (Computer Science)
Other Threads in the VB.NET Forum
- Previous Thread: User Controls as Forms within a Form
- Next Thread: Help with deleting records from text file
| Thread Tools | Search this Thread |
.net .net2008 2008 access account advanced application array basic beginner browser button buttons center click code combo cuesent data database datagrid datagridview date datetimepicker designer dissertation dissertations dissertationtopic excel exists fade filter forms generatetags gridview html images input insert intel internet listview map mobile module monitor msaccess net number objects open panel passingparameters pdf picturebox picturebox2 port position print printing problem regex remove right-to-left save search searchvb.net select serial settings shutdown socket sqldatbase sqlserver survey temperature textbox timer timespan transparency txttoxmlconverter update user usercontol vb vb.net vb.netformclosing()eventpictureboxmessagebox vba vbnet visual visualbasic visualbasic.net visualstudio.net visualstudio2008 web winforms wpf wrapingcode xml year





