首页 > 代码库 > C#获得数据库指定字段的值

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

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

如下,获得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#获得数据库指定字段的值