读书人

怎么取select a from B where c = quot;1quot;

发布时间: 2012-01-23 21:57:28 作者: rapoo

如何取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();

读书人网 >VB Dotnet

热点推荐