|
-
Mar 1st, 2004, 06:01 AM
#1
Thread Starter
Junior Member
Account Id Generator
Code:
private void MedIDGenerator()
{
try
{
oleDbConnection1.Open();
oleDbDataAdapter1.SelectCommand.CommandText = "SELECT [Med ID] FROM Pharmacy ORDER BY [Med ID] DESC" ;
oleDbDataAdapter1.SelectCommand.ExecuteNonQuery();
int recordCount = (Int32) oleDbDataAdapter1.SelectCommand.ExecuteScalar();
//update the Med ID textbox with the Number of records present plus one.
recordCount++;
txtMedID.Text = recordCount.ToString() ;
}
catch(Exception e)
{
MessageBox.Show("Error in connecting! "+e.ToString(), "Error");
}
finally
{
oleDbConnection1.Close();
oleDbConnection1.Dispose();
}
how do i make the counter start from 0, at this moment if the database is empty it gives me a logical error..but if there's a record in it, it works fine...what's wrong...how do i make it start from zero?...
thx in advance
-
Mar 8th, 2004, 11:39 AM
#2
Addicted Member
Hi,
I am not much good at this stuff, but thought I would try and help!
You could try :
Code:
SELECT Max([Med ID]) + 1 as Next_Value FROM Pharmacy
Not sure what the results would be for an empty row (1 I think).... depends on the database.
Maybe this helps?
DJ
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|