hai,
please help me to move the record in the table.
i need this very urgently
Two different problems are commonly called "move the record" — navigation (Next/Previous in the UI) or physically changing row order in the database. seemed to mean navigation ("move next in vb") and correctly pointed out iteration approaches, but for a WinForms VB.NET UI the simplest, most robust solution is to bind your results to a BindingSource and call its MoveNext/MovePrevious. A DataReader is forward-only and fine for streaming reads, but not ideal when you need random access or UI navigation.
Example (WinForms, VB.NET — BindingSource bound to a DataTable/DataSet):
' bs is a BindingSource bound to your table
Private Sub btnNext_Click(sender As Object, e As EventArgs) Handles btnNext.Click
If bs.Position < bs.Count - 1 Then bs.MoveNext()
DisplayCurrent()
End Sub
Private Sub btnPrevious_Click(sender As Object, e As EventArgs) Handles btnPrevious.Click
If bs.Position > 0 Then bs.MovePrevious()
DisplayCurrent()
End Sub
Private Sub DisplayCurrent()
Dim drv As DataRowView = TryCast(bs.Current, DataRowView)
If drv IsNot Nothing Then lblValue.Text = Convert.ToString(drv("SomeColumn"))
End Sub If this is an ASP.NET WebForms page, persist the current row index in ViewState (or a session) and rebind the row to controls on each click; a DataTable in memory gives you indexed access.
If you actually want to reorder rows in the database (move up/down in a list), add an integer SortOrder column and swap values inside a transaction so you never end up with duplicate orders. After updating the DB, refresh the in-memory table and call bs.ResetBindings(False) so the UI reflects the new order.
Troubleshooting tips: guard against DBNull when reading fields, ensure the BindingSource.DataSource is set before calling MoveNext, and prefer parameterized SQL and transactions when changing persistent order to avoid race conditions.
I am sorry but i can't understand you ..
do you mean move all the record data from one position to another .. and give me breif decription of the table design and the moving purpose in order to help you ..
hai,
just moving the record in the table, ie move next in vb.
understand.
HI
ok i understood you ..
in C#
-You can use the dataAdapter which fill the dataset..
the dataset is like the tow dimentional array ,that you can get any record from it by its indecies ..
e.g dataset1.Tables[0].Rows[0][2].ToString();
by simple for loop you can get all the data from the dataSet (note that the limit of the loop will be dataSet1.Tables[0].Rows.Count)..
-You can use the dataReader which is assigned to the return of the ExecuteReader() method of the command , then every time the dataReader make the Read() method you can move next.
////////////
dataReader1.Read(); // the first read
while(dataReader1.HasRows())
dataReader1.Read();
// get data here by dataReader1.GetString() or other Get.. methods
/////////////
I wish i could help you
bye
hai,
thanks for ur help. and i will check it and tell to u
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.