C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » ASP.NET »

Auto generate


Posted Date: 04 Jul 2009      Posted By: gopal.net      Member Level: Gold     Points: 1   Responses: 4



hi

this my code . iam auto generating the PO Number which is in format PO-OOO1.

I want to auto generate. By this code iam getting PO-1 like this. iwant it PO-0001.

suggestions required in code



Name = "PO-";
SqlCommand cmd = new SqlCommand("Select top 1 * from Purordr order by purordr_pur_ordno desc ", con);
con.Open();
SqlDataReader d = cmd.ExecuteReader();
if (d.Read() == true)
{
str = d["purordr_pur_ordno"].ToString();//it is String
}
for (int index = 0; index < str.Length; index++)
{
c[index] = str[index];

}
con.Close();
int x = Convert.ToInt32(c[3].ToString());
int y = Convert.ToInt32(c[4].ToString());
int z = Convert.ToInt32(c[5].ToString());
int A = Convert.ToInt32(c[6].ToString());

int PNo = Convert.ToInt32(x * Math.Pow(10, 3)) + Convert.ToInt32(y * Math.Pow(10, 2)) + Convert.ToInt32(z * Math.Pow(10, 1)) + Convert.ToInt32(A * Math.Pow(10, 0));
int PN = PNo + 1;
tb_ordrno.Text = Name + PN.ToString();





Responses

Author: Anil Chalasani    04 Jul 2009Member Level: GoldRating: 2 out of 52 out of 5     Points: 2

use like this
tb_ordrno.Text = Name + PN.ToString("0000");

Thanks & Regards
Anil Chalasani.



Author: Manigandan    04 Jul 2009Member Level: GoldRating: 2 out of 52 out of 5     Points: 2

Hi,

Instead of giving the 0001 as integer,
Give it as a Nvarchar.

Thanks,
Mani
http://manicse85.blogspot.com/



Author: Devendra    04 Jul 2009Member Level: GoldRating: 2 out of 52 out of 5     Points: 2

Dear,

Why you are not using Stuff instead of Writing procedure just use stuff formula to write these.

See How to write stuff in Sql Server and use that it would be better generate auto no.

thanks
devendra



Author: Sucharitha    07 Jul 2009Member Level: SilverRating: 2 out of 52 out of 5     Points: 2

dim num as integer
dim s1 as string

c.cmd = New SqlCommand("select IsNull(Max(po_id),0)+1 from purorder_tbl ", c.con)
c.con.Open()
num = c.cmd.ExecuteScalar()
c.con.Close()


s1 = "000"

textbo1.text= s1 & num



Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : Query for joining two tables
Previous : Prblm with required field validator
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use