Wrox Home  
Search P2P Archive for: Go

  Return to Index  

ado_dotnet thread: getting records from database....


Message #1 by blueei@h... on Sat, 22 Dec 2001 04:30:30
hi,

does anyone knows how to get the last record of the column in a databae 

table (SQL server)? and also the first record of another column in the 

same table?

please kindly advise! 

Thank you!
Message #2 by "Amir wyne" <amirwyne@h...> on Sun, 23 Dec 2001 18:51:39 +0000
hi,

In ADO.NET there is no direct method available to get the first and the last 

records, as we were given in previous ADO versions.you can try the following 

code which has been test. hope you would get your answer.



'// Declare the following according to your own macthing names



Dim MyTable as DataTable=new DataTable()



MyDataTable=MyDataSet.Table("TableName")

or

MyDataTable=MyDataSet.Table(IndexValue)





Dim ResultRecord as DataRow

Dim MyDataColumn as DataColumn=MyDataTable.Columns("MyColumnName")



Dim LastRecordPointer as Integer=MyDataTable.DefaultView.Count - 1

Const FirstRecordPointer as Integer=0



ResultRecord=MyDataTable.DefaultView(LastRecordPointer).Row



'ResultRecord IS YOUR ENTIRELY LAST RECORD, YOU CAN GET THE VALUE

' OF ANY COLUMN BY GIVEN THE COLUMN INDEX OR NAME AS SUCH



Dim MyValue



MyValue=ResultRecord(MyDataColumn)



'FOR OBTAINING FIRST RECORD, YOU CAN USE THE SAME LINES BUT SWAP THE



'FirstRecordPointer with LastRecordPointer.ALSO YOU CAN CHANGE THE COLUMN BY 

GIVING



'DIFFERENT COLUMN INDEX OR NAME.



Thanks.

AMIR WYNE







>From: blueei@h...

>Reply-To: "ADO.NET" <ado_dotnet@p...>

>To: "ADO.NET" <ado_dotnet@p...>

>Subject: [ado_dotnet] getting records from database....

>Date: Sat, 22 Dec 2001 04:30:30

>

>hi,

>does anyone knows how to get the last record of the column in a databae

>table (SQL server)? and also the first record of another column in the

>same table?

>please kindly advise!

>Thank you!






_________________________________________________________________

Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.




  Return to Index