01.
private
void
GenerateID()
02.
{
03.
string
_runPIDNew =
string
.Empty;
04.
05.
if
(con.State == ConnectionState.Open) con.Close();
06.
con.ConnectionString =
"Data Source=127.0.0.1;Initial Catalog=dbProduct;Integrated Security=True"
;
07.
con.Open();
08.
09.
sb.Remove(0, sb.Length);
10.
sb.Append(
" select max(ProductId) as maxID from product "
);
11.
sql = sb.ToString();
12.
13.
da =
new
SqlDataAdapter(sql, con);
14.
if
(ds.Tables[
"dtProductId"
] !=
null
)
15.
{
16.
ds.Tables[
"dtProductId"
].Clear();
17.
}
18.
da.Fill(ds,
"dtProductId"
);
19.
20.
DataTable dt =
new
DataTable();
21.
dt = ds.Tables[
"dtProductId"
];
22.
23.
if
(dt.Rows.Count != 0)
24.
{
25.
string
_oldID = dt.Rows[0][
"ProductId"
].ToString();
26.
int
_runningID =
int
.Parse(_oldID.Substring(3, 5).ToString());
27.
int
_runningIDNew = _runningID + 1;
28.
_runPIDNew =
"PID"
+ _runningIDNew.ToString(
"00000"
);
29.
}
30.
else
31.
{
32.
_runPIDNew =
"PID00001"
;
33.
}
34.
35.
}