关于创建新的ID [英] about creating new id

查看:101
本文介绍了关于创建新的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的表中有两个字段,即comp_id,它是自动递增的....另一个是registration_id.
但是我想生成一个存储在Registration_id字段中的新ID.该ID的格式如下,即CO1,CO2等... CO默认为,而1,2为comp_id Feild值.... so如何写鳕鱼?????
请给我发送代码....

in my table two feilds ie comp_id which is auto increment....and another is registration_id.
but i want to generate new id which is store in Registration_id feild..that ID is in following format ie.CO1,CO2,etc ...that CO is By default and 1,2 is comp_id Feild value.....so how to write cod?????
plz send me code....

推荐答案

听起来像您想生成字母数字ID的声音.如果是这样,请看这里:
在SQL Server表中自动生成字母数字ID [ ^ ]
Sounds like you want to generate Alphanumeric ID''s. If so, look here:
Auto Generate AlphaNumeric ID’s in a SQL Server Table[^]


引用此内容
http://sqlanddotnetdevelopment.blogspot.in/2011/01/auto- generate-alphanumeric-ids-in-sql.html [ ^ ]
http://dotnetadda.blogspot.in/2010/05/auto- generate-alphanumeric-ids-in-sql.html [ ^ ]
Refer this
http://sqlanddotnetdevelopment.blogspot.in/2011/01/auto-generate-alphanumeric-ids-in-sql.html[^]
http://dotnetadda.blogspot.in/2010/05/auto-generate-alphanumeric-ids-in-sql.html[^]


像这样尝试
Try like this
SqlConnection con=new SqlConnection (ConfigurationManager.ConnectionStrings ["con"].ConnectionString ); 
    
    SqlDataAdapter  da = new SqlDataAdapter("select * from sample order by id desc", con);
    DataSet    ds = new DataSet ();
        da.Fill(ds);
       int id;
        int coid = Convert.ToInt32(ds.Tables[0].Rows[0][0].ToString());

        if (ds.Tables[0].Rows.Count > 1)
        {
            id = coid + 1;
        }
        else { id = 1; }
        string  rid;
        rid = "CO" + id;
        con.Open();
        SqlCommand cmd = new SqlCommand("insert into sampleid(rid) values('"+rid +"')", con);
        cmd.ExecuteNonQuery();


这篇关于关于创建新的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆