September 17, 2010 at 7:49 pm
hi all...,
i create a registration form and it'll generate AccounNo for user after they click "SAVE" button.
my database AccountNo start from 300000000
it's generate ID after >300000000
if i register a person it will register to 300000001
let's say i have AccountNo-
300000001
300000002
300000004
300000005
i dun have "300000003"
i want to get that Account No to my registration...
when i click "SAVE" it's have to search the minimum Account No from database and add user...
how to do this..can anyone modify this code to read min AccountNo from database..
here's the code that i have using :
try
{
connection.Open();
#region Generating a newAccNo
SqlCommand newAccNoCommand = connection.CreateCommand();
newAccNoCommand.CommandText = "SELECT TOP 1 AccNo FROM Debtor ORDER BY AccNo DESC";
newAccNoCommand.CommandType = CommandType.Text;
int minCurrentAccNo = 0;
try
{
if (!int.TryParse(newAccNoCommand.ExecuteScalar().ToS tring(), out minCurrentAccNo))
{
minCurrentAccNo = defaultAccNo;
}
}
catch
{
minCurrentAccNo = defaultAccNo;
}
int newAccNo = minCurrentAccNo + 1;
newAccNoCommand.Dispose();
#endregion
September 17, 2010 at 8:41 pm
I would suggest reading the following
http://www.sqlservercentral.com/articles/Datetime+Manipulation/61822/
AND the comments on the article describing some different approaches.
September 18, 2010 at 6:06 pm
bitbucket-25253 (9/17/2010)
I would suggest reading the followinghttp://www.sqlservercentral.com/articles/Datetime+Manipulation/61822/
AND the comments on the article describing some different approaches.
Oh my, no. Sorry Ron.
@Jeev... you're just asking for a computational world of hurt by trying to "fill in" all the missing account numbers that you may end up with. Just use an IDENTITY column and don't worry if a few account numbers end up missing because of people doing rollbacks or pressing the "Back Button" or what have you. Seriously... filling in missing account numbers is one of the worst things you could to to an SQL Server database.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply