如何通过将字符串与数字连接来生成ID [英] how to generate an id by concatenating string with the number
本文介绍了如何通过将字符串与数字连接来生成ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
通过使用c#代码以这种格式生成ID就像PIR00001
generating an id is like PIR00001 in this format by using c# code
推荐答案
如果要在C#中生成ID,那么以下代码可能会帮助您
If you want to generate the id in C#, then following code may help you
int id = 1;
string stdId = "PIR" + id.ToString().PadLeft(5, '0');
使用System.Data.SqlClient;
在您的按钮的点击事件中编写此方法
string connect =数据源= .;初始目录=您的数据库名称;集成安全性=真";
SqlConnection con =新的SqlConnection();
con.ConnectionString = connect;
con.Open();
SqlDataAdapter adp =新的SqlDataAdapter(从学生中选择Student_id",con);
DataSet ds = new DataSet();
adp.Fill(ds);
int x = ds.Tables [0] .Rows.Count;
x ++;
字符串abc = x.ToString();
字符串转储="PIR0000";
txtstudentid.Text = dump + abc;
con.Close();
一旦发现有用,请评价我的答案
谢谢与问候
基:rose:
using System.Data.SqlClient;
write this method in ur button''s click event
string connect = "Data Source=.;Initial Catalog=name of ur database;Integrated Security=True";
SqlConnection con = new SqlConnection();
con.ConnectionString = connect;
con.Open();
SqlDataAdapter adp = new SqlDataAdapter("select student_id from student", con);
DataSet ds = new DataSet();
adp.Fill(ds);
int x = ds.Tables[0].Rows.Count;
x++;
string abc = x.ToString();
string dump = "PIR0000";
txtstudentid.Text = dump + abc;
con.Close();
Please Rate my answer once u find it useful
Thanks & Regards
Radix :rose:
这篇关于如何通过将字符串与数字连接来生成ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文