asked on
public int GetRecordNumber(string seekKey)
{
int recordNumber = -1;
if (itemMasterResultSet_.Seek(DbSeekOptions.FirstEqual, seekKey))
{
while (itemMasterResultSet_.ReadPrevious())
{
recordNumber++;
}
}
return recordNumber;
}
ASKER
ASKER
public int GetCurrentRecNum()
{
SqlCeCommand sqlCeSelectCommand = null;
if (this.ItemNumber == null)
{
return -1;
}
try
{
// Create a command object & set the required properties
sqlCeSelectCommand = sqlCeConnection.CreateCommand();
sqlCeSelectCommand.CommandText = @"SELECT COUNT(*) AS RecCount
FROM Item
WHERE (ItemNumber < N'" + ItemNumber + "')";
sqlCeSelectCommand.IndexName = "PK_Item";
sqlCeSelectCommand.CommandType = System.Data.CommandType.Text;
// Execute the command to get the record count as an object
object currentRecNum = sqlCeSelectCommand.ExecuteScalar();
// Return the record number converted to an integer
return (int)currentRecNum;
}
catch (Exception)
{
throw;
}
}
ASKER
Microsoft SQL Server is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.SQL Server is available in multiple versions, typically identified by release year, and versions are subdivided into editions to distinguish between product functionality. Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning.
TRUSTED BY
ASKER
Thanks for your input. Great minds think alike. There are a couple of tables that are read only where that's exactly what I've done - added an "OrdinalPosition" field which is, of course, the record number. Using that approach on tables that are editable won't work because the numbers would be wrong as soon as a record was deleted.
I'm not too crazy about reading the entire database into memory because handheld memory is somewhat constrained.
This problem may just be an oversite on the part of Microsoft. If that's the case, I'll probably stick with my current scheme of including an OrdinalPosition on the read only tables and counting the records on the others. BTW (so you don't think I'm a dullard), the code snippet I provided was a simplified version just to show the principle. The real code stores the record number in a private (class) field and marks it as needing to be updated whenever the record selection changes.
JCC