TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
How to make a Random Number with Unique Code
Mukesh Rajaram
May 15
2016
Code
764
0
1
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
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