首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

怎么取select a from B where c = "1"中a值

2012-01-23 
如何取select a from B where c 1中a值我是初学者,请教一个问题:怎么把SQL语句选择的值放在文本里如:s

如何取select a from B where c = "1"中a值
我是初学者,请教一个问题:怎么把SQL语句选择的值   放在   文本里  
如:   select   a   from   B   where   c   =   "1 "  
怎么才能   把   a   的值给   Label.text。请大家指点

[解决办法]
使用ExecuteScalar足够了,没有必要使用一个Reader:

SqlConnection cn = new SqlConnection( "server=.;uid=sa;pwd=;database=dataBase ");
cn.Open();
SqlCommand cm = cn.CreateCommand();
cm.CommandText = "select a from B where c = '1 ' ";
object obj = cm.ExecuteScalar();
if (obj != null)
{
this.textBox.Text = obj.ToString();
}
cn.Close();

热点排行