日期:2014-05-20  浏览次数:20838 次

请教个读取数据的问题
是WEB程序

                //read   HotKey   from   database
                SqlLoadHotKey.SelectCommand   =   "SELECT   HotKey   FROM   [TableHotkey]   where   ID   =   1 ";
                string   s   =   上面命令执行的结果

我的意思是如何执行上面的语句后,把返回结果给s.
HotKey字段在表中是字符串格式


------解决方案--------------------
try..

SqlConnection con=new SqlConnection( "连接字符串 ");
SqlLoadHotKey.SelectCommand = "SELECT HotKey FROM [TableHotkey] where ID = 1 ";
SqlLoadHotKey.SelectCommand.Connection=con;
con.Open();
string s=Convert.ToString(SqlLoadHotKey.SelectCommand.ExecuteScalar());
con.Close();