如何从Sql获取序列号并存储在我的C#代码中 [英] How Can I Get The Serial Number From Sql And Store In My C# Code

查看:88
本文介绍了如何从Sql获取序列号并存储在我的C#代码中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

在此我用SQL开发C#应用程序。我的问题是如何从sql数据库中获取最大序列号并将其存储在C中的变量中#



谢谢

Indrajit Dasgupta

Hi All,
Herewith I am developing C# application with SQL. My question is how to get maximum serial number from sql Database and store it in a variable in C#

Thanks
Indrajit Dasgupta

推荐答案

SqlConnection xconn=new SqlConnection(ConfigurationManager.ConnectionStrings["DbConnect"].ToString());

SqlCommand xcmd=new SqlCommand("select max(serialNum) from dbo.YourTable",xconn);
int num=0;
try
{
xconn.Open();
num=xcmd.ExecuteScalar();
Console.WriteLine("Max serial number is {0}",num);
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
xconn.Close();
}





以上代码可以帮助您入门。



问候

Anurag



The above code should get you started.

Regards
Anurag


这篇关于如何从Sql获取序列号并存储在我的C#代码中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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