注册号码问题 [英] Registration number issue

查看:42
本文介绍了注册号码问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在开发学生注册表格。

为此,我在sql server中创建了一个表格,其中包含表格编号是主键并且有标识栏

我选择最后一个表格编号并添加一个表格编号并在屏幕上显示为新的注册编号。问题是如果多个用户访问表单,每个用户都有相同的注册号。但是逻辑说每个用户应该有不同的注册号。我也是根据这个注册号保存图像。因此产生了多个具有相同编号的图像。



你能帮忙解决这个问题吗?



I am developing a student registration form.
For this I created a table in sql server in which form number is primary key and having identity column
I pick the last form number and adding one to it and displayed it on screen as new registration number. the issue is if multiple user access the form every user has same registration number.but the logic says that every user should have different registration number.I am also saving image on the basis of this registration number.Therefore multiple images with same number is resulted.

Could you please help to solve this problem?

推荐答案

使用随机函数来显示注册前端的数字。在新栏中插入该号码。

例如。



随机oRandom = new Random();

int iNum = oRandom.Next(1000,1000000);
Use random function to show the registration number in the front end. Insert that number in new column.
eg.

Random oRandom = new Random();
int iNum = oRandom.Next(1000, 1000000);


对不起迟到

这里是示例

MySqlConnection con = new MySqlConnection( server = localhost; database = data; user = root; pwd =;);

con.Open();



MySqlTransaction trans = con.BeginTransaction();



试试



{

int registration_ID = create_registrationNo();



string sql =insert INTO transaction_ledger(trans_id,voucher_id)VALUES(registration_ID,1173);







新的MySqlCommand(sql,con,trans).ExecuteNonQuery();





trans.Commit();

}

catch(例外情况)

{



trans.Rollba ck();

}

终于

{

con.Close();

}





------------------

另一种方法,我们在创建id时插入数据,如果已经存在,那么你可以再次跳转到创建id,这样它就会再次生成id。





createid:

int_id = Create_Intimation_ID();

INTIMAT_ID = int_id;

尝试

{

cl.Insert_claimIntimation(INTIMAT_ID,Convert.ToString(ViewState [IMEI_ID]));

}

catch(系统.Data.SqlClient.SqlException ex)

{

if(ex.Number == 2627)

{

转到createid;

}

}
Sorry for late
here is example
MySqlConnection con = new MySqlConnection("server=localhost;database=data;user=root;pwd=;");
con.Open();

MySqlTransaction trans = con.BeginTransaction();

try

{
int registration_ID=create_registrationNo();

string sql = "insert INTO transaction_ledger (trans_id,voucher_id) VALUES (registration_ID,1173)";



new MySqlCommand(sql, con, trans).ExecuteNonQuery();


trans.Commit();
}
catch (Exception ex)
{

trans.Rollback();
}
finally
{
con.Close();
}


------------------
another method here we insert data when id created and if already exists then you can jump to create id again so that it will generate id again.


createid:
int_id = Create_Intimation_ID();
INTIMAT_ID = int_id;
try
{
cl.Insert_claimIntimation(INTIMAT_ID,Convert.ToString(ViewState["IMEI_ID"]));
}
catch (System.Data.SqlClient.SqlException ex)
{
if (ex.Number == 2627)
{
goto createid;
}
}


是的有多种方式

你可以使用事务锁然后这将创建每个用户将获得新的注册号
Yes there are multiple ways
you can use transaction lock then this will create every user will get new registration number


这篇关于注册号码问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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