C#SQL如何在标签中显示bd的增量数字,当是字母数字时 [英] C# SQL how to show in label a incremenial number from bd when is alphanumeric

查看:77
本文介绍了C#SQL如何在标签中显示bd的增量数字,当是字母数字时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在标签中出现一个在sql bd中的增量字段,我想拥有下一个#。

ex:在我的bd中我完成了AA002我想要显示在AA003标签中。



我尝试过:



SqlConnection sc = new SqlConnection(Data Source = 7KH9R22 \\SQLEXPRESS; Integrated Security = TRUE; Initial Catalog = RSE);

//添加+1时没有出现但是当我删除+时1显示当前最后一个#bd



SqlCommand cmd = new SqlCommand(SELECT MAX(CLIENTno)+1 FROM FROM CLIENT,sc);





cmd.CommandType = CommandType.Text;

cmd.Connection.Open();

object o = cmd.ExecuteScalar();

if(o!= DBNull.Value)label16.Text = o.ToString();

sc.Close( );

I want to make appear in a label an incremential field that is in a sql bd, I want to have the next #.
ex: in my bd I am done to AA002 I want to show in the label AA003.

What I have tried:

SqlConnection sc =new SqlConnection("Data Source=7KH9R22\\SQLEXPRESS;Integrated Security=TRUE;Initial Catalog=RSE");
//nothing appear when add +1 but when i remove +1 is show the current last # in bd

SqlCommand cmd = new SqlCommand("SELECT MAX (CLIENTno)+1 FROM CLIENT ", sc);


cmd.CommandType = CommandType.Text;
cmd.Connection.Open();
object o = cmd.ExecuteScalar();
if (o != DBNull.Value) label16.Text = o.ToString();
sc.Close();

推荐答案

不要。

这是一个非常非常糟糕的主意 - 而且你不需要它。



SQL Server是一个多用户环境,这意味着空闲用户将显示相同的下一个号码。那么谁得到它?第一个做INSERT。其他人会怎么样?好吧,如果你很幸运,应用程序崩溃,你的用户讨厌你。

如果你运气不好,你的数据库会因数据不一致而更新,你会在你的客户面前把它全部整理好开始起诉你为他们从未订购的物品开票,或者因为你把它们送到别处而未到货的货物。



这是一个非常新的错误,并且你应该避免它 - 新的ID是在执行插入时由数据库生成的,之后又被拉回到你的应用程序。在数据进入数据库之前,没有人需要它,诚实 - 在打开之前你需要知道你的银行账号。
Don't.
It's a very, very bad idea - and you don't need it.

SQL Server is a multiuser environment, which means that ever "idle" user will be showing the same "next" number. So who gets it? The first to do the INSERT. What happens to the others? Well, if you are lucky, the app crashes and your users hate you.
If you are unlucky, your database gets updated with inconsistent data and you get the horrible job of sorting it all out before your customers start to sue you for billing them for items they never ordered, or goods that didn't arrive because you sent them elsewhere.

This is a very rookie mistake, and you should avoid it - the new ID is generated by the database when the insert is performed, and pulled back to your app afterwards. Nobody needs it before the data is in the DB, honest - any more than you need to know your bank account number before it is opened.


这篇关于C#SQL如何在标签中显示bd的增量数字,当是字母数字时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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