C#查询SqlServer数据库并返回单个值的方法
更新时间:2015年06月29日 15:12:40 作者:pythoner
这篇文章主要介绍了C#查询SqlServer数据库并返回单个值的方法,涉及C#操作SQLServer数据库查询的相关技巧,需要的朋友可以参考下
本文实例讲述了C#查询SqlServer数据库并返回单个值的方法。分享给大家供大家参考。具体实现方法如下:
static public string GetSqlAsString(string sqlText, SqlParameter[] sqlParameters, string databaseConnectionString) {
string result = "";
SqlDataReader reader;
SqlConnection connection = new SqlConnection(databaseConnectionString);
using (connection) {
SqlCommand sqlcommand = connection.CreateCommand();
sqlcommand.CommandText = sqlText;
if (sqlParameters != null) {
sqlcommand.Parameters.AddRange(sqlParameters);
}
connection.Open();
reader = sqlcommand.ExecuteReader();
if (reader != null)
if (reader.Read()) {
result = reader.GetString(0);
}
}
return result;
}
希望本文所述对大家的C#程序设计有所帮助。
相关文章
C#仪器数据文件解析Excel文件的方法浅析(xls、xlsx)
这篇文章主要给大家介绍了关于C#仪器数据文件如何解析Excel文件的方法,包括解析xls、xlsx两种格式,文中介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧。2017-10-10


最新评论