01.
public
void
maxKey()
02.
{
03.
string
s =
null
;
04.
int
n = 0;
05.
Sql =
"SELECT MAX(RIGHT(p_id,4)) AS maxKey "
+
"FROM tbBudgets "
+
"WHERE p_year='"
+ ddlp_year.Text +
"'"
;
06.
db.connectdb();
07.
cm =
new
SqlCommand(Sql, db.cn);
08.
rs = cm.ExecuteReader;
09.
rs.Read();
10.
if
(
object
.ReferenceEquals(rs(
"maxKey"
), DBNull.Value)) {
11.
s =
"0001"
;
12.
}
else
{
13.
n = rs(
"maxKey"
);
14.
n += 1;
15.
s = n.ToString(
"0000"
);
16.
}
17.
db.closedb();
18.
19.
lblp_id.Text =
"pb"
+ ddlp_year.Text.Substring(2, 2) + s;
20.
21.
Sql =
null
;
22.
23.
}