码迷,mamicode.com
首页 > 数据库 > 详细

C#获得数据库指定字段的值

时间:2016-11-02 18:12:19      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:cut   nbsp   sqlite   exe   reader   open   本地变量   select   code   

 获得数据库指定字段的值,赋给本地变量

如下,获得userinfo数据表里的字段"userid"、"orgid",

string userid="";
string orgid="";
using (SQLiteConnection con = new SQLiteConnection(Constants.DATA_SOURCE))
{
    con.Open();
    using (SQLiteCommand cmd = new SQLiteCommand())
    {
        cmd.Connection = con;
        cmd.CommandText = string.Format("select * from userinfo t ");
        using (SQLiteDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
        {
            while(dr.Read())
            {
                userid = dr["userid"].ToString();
                orgid = dr["orgid"].ToString();
            }

        }

    }
}

 

C#获得数据库指定字段的值

标签:cut   nbsp   sqlite   exe   reader   open   本地变量   select   code   

原文地址:http://www.cnblogs.com/Donnnnnn/p/6023421.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!