Here is an example to generate random number as well as string..
Hope it helps you to understand the logic..and you can create whatever condition you want.
StringBuilder builder = new StringBuilder();
builder.Append(RandomString(4, true));
builder.Append(RandomNumber(1000, 9999));
Generate random number
private string RandomString(int size, bool lowerCase)
{
StringBuilder builder = new StringBuilder();
Random random = new Random();
char ch;
for (int i = 0; i < size; i++)
{
ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65)));
builder.Append(ch);
}
if (lowerCase)
return builder.ToString().ToLower();
return builder.ToString();
}
Generate Random Number
private int RandomNumber(int min, int max)
{
Random random = new Random();
return random.Next(min, max);
}
You may also apply query to generate serial number
string sqlQuery = "select max(" + colName + ") + 1 from " + tblName;
If you still have any query don't hesitate to ask..
Happy coding.