Results 1 to 2 of 2

Thread: Account Id Generator

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2004
    Posts
    29

    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
    Arvinder Gill

  2. #2
    Addicted Member DJ_Catboy's Avatar
    Join Date
    Jan 2003
    Location
    Suffolk, UK
    Posts
    159
    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
  •  



Click Here to Expand Forum to Full Width