.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> VB.Net >> Post New QuestionBookmark and Share Subscribe to Forum

How to get the current row in SQL Server 2005

Posted By: Jai     Posted Date: September 24, 2008    Points:2   Category :VB.Net
Hi,
I am using VB.NET and SQL Server 2005. I need to traverse through the Database.. it looks to be simple but I am not able to figure out exactly.

I use textboxes to show the columns in the database. When I click the next button, I have to show the next row values. I tried to get the current row or current row number. How to do this. What is the function we need to call to get the current row of data. I used this code

Dim mytableRows() As System.Data.DataRow
mytableRows = myAdapter.Getmytable.Select()

I get all the data in mytableRows. There is no function for next and previous like first, last. There is function called FindAt. If I know the current position, I can give current position +1.

Any Help??

Thanks

Responses
Author: Amit Mehra             
Posted Date: September 24, 2008     Points: 5   

Hi,
you can use DataSet for this. Fill your Dataset and while fetcing the data you can do like this

DataRow dr = ds.Tables[0].Rows[0]; //ds is your DataSet and you can increment the rows index

Thanks,
Amit
Please "Mark As Answer " if this post help you.
Author: Jai             
Posted Date: September 24, 2008     Points: 5   

Hi,
I think
DataRow dr = ds.Tables[0].Rows[0]; will give the first row.

But I dont want the first row. My current record can be 4th row. Then when I click next I need to go to the 5th row. How will I get the number 4 as the row number.

Author: Amit Mehra             
Posted Date: September 24, 2008     Points: 5   

Yes you are right so you can increment the rows index like this

DataRow dr = ds.Tables[0].Rows[4];

or you can use ForEach loop

Thanks,
Amit
Please "Mark As Answer " if this post help you.
Author: Jai             
Posted Date: September 24, 2008     Points: 5   

My question is how will I know that I am in 4th row.

Author: Jai             
Posted Date: September 24, 2008     Points: 5   

Hi,

I dont know the rownumber. I do not want the data in particular row. I want the rownumber for the data displayed in the textboxes.

Did u mean that I have to compare the value in each of the column (say primary key) with the textbox value and if it matches, then

DataRow dr = ds.Tables[0].Rows[CurrentRow+1];

Will this work.. or is it not round about.

Author: Amit Mehra             
Posted Date: September 24, 2008     Points: 5   

Hi,
You said that whatever the number displays in the textbox that row you have to go so in that case you can try like this

int counter = Convert.ToInt32(TxtBox1.Text);
DataRow dr = ds.Tables[0].Rows[counter];

Thanks,
Amit
Please "Mark As Answer " if this post help you.
Author: Savi3             
Posted Date: September 27, 2008     Points: 5   

Hey its Simple yaar,

Author: Savi3             
Posted Date: September 27, 2008     Points: 5   

U've to use datareader to fetch the each records from the db

Author: Savi3             
Posted Date: September 27, 2008     Points: 5   

Sorry some pbm in system

Author: Savi3             
Posted Date: September 27, 2008     Points: 5   

Hey whenever i hit enter key it posted.So only the above pbm occur. Now come to our point
 while(dr.read){ i=1; then u check use the if condition which record is u want. here i specifies u r rownumber) } Hope u understand this. Happy programming.

Author: Santosh             
Posted Date: October 07, 2009     Points: 5   

hi
if any unique column is there then u can do it easily.

just put a hidden textbox like txtID(unique column)
then in case of next or previous button click u write this code

let the the data u want show the textbox is (txtUserName)

[Code]
dim nextindex as integer
dim preindex as integer
if txtId.text = "" then
txtId.text = dsUser.table(0).rows(0).item(0)
txtUserName.text =dsUser.table(0).rows(0).item(1)
else
for i as integer = 0 to dsUser.table(0).rows.count-1
if dsUser.table(0) = txtid.text.trim() then
nextindex = 1
end if
next
txtId.text = dsUser.table(0).rows(nextindex).item(0)
txtUserName.text =dsUser.table(0).rows(nextindex).item(1)
end if
[/Code]

try with above code,any problem reply.


with regards
santosh
http://santoshdotnetarena.blogspot.com/



Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend