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#程序设计有所帮助。


标签:SQLite

相关阅读 >>

android数据存储之Sqlite使用

android Sqlite基本用法详解

详解android文件描述符

django基础之数据库操作方法(详解)

sql学习之case when then else end的用法

rxjava2_flowable_Sqlite_android数据库访问实例

Sqlite如何迁移到mysql脚本的实例介绍

flutter数据库的使用方法

windows平台python连接Sqlite3数据库的方法分析

将txt文本内容导入Sqlite的方法

更多相关阅读请进入《Sqlite》频道 >>


数据库系统概念 第6版
书籍

数据库系统概念 第6版

机械工业出版社

本书主要讲述了数据模型、基于对象的数据库和XML、数据存储和查询、事务管理、体系结构等方面的内容。



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...