Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
How to make a Random Number with Unique Code
WhatsApp
Mukesh Rajaram
May 15
2016
818
0
1
protected
void
Page_Load(
object
sender, EventArgs e)
{
autogenerated();
//its a call for auto no. function
}
void
autogenerated()
{
string
connection = ConfigurationManager.ConnectionStrings[
"ConnectionString"
].ConnectionString;
SqlConnection con =
new
SqlConnection(connection);
str =
"select max(abid) as abid from abstracted"
;
com =
new
SqlCommand(str, con);
con.Open();
count = Convert.ToInt16(com.ExecuteScalar()) + 1;
Label1auto.Text =
"AB00"
+ count.ToString();
con.Close();
}
Html code
<asp:Label ID=
"Label1auto"
runat=
"server"
Visible=
"true"
></asp:Label>
Data table scripts
CREATE
TABLE
[dbo].[abstracted](
[id] [
int
] IDENTITY(1,1)
NOT
NULL
,
[abid] [nvarchar](255)
NULL
,
[abno] [nvarchar](255)
NULL
,
[abtype] [nvarchar](255)
NULL
,
[category] [nvarchar](255)
NULL
,
[
name
] [nvarchar](255)
NULL
,
[design] [nvarchar](255)
NULL
)
ON
[
PRIMARY
]
Web config
<
connectionStrings
>
<!--<add name="ConnectionString" connectionString=" Data Source=.\SQLEXPRESS;database=dmcg_admin;Integrated Security=True" providerName="System.Data.SqlClient" />-->
</
connectionStrings
>
Output
Auto no -AB001
make a Random Number
Unique Code
Up Next
How to make a Random Number with Unique Code