加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 在asp.net中的标签中显示SQL查询结果

发布时间:2020-12-16 00:02:23 所属栏目:百科 来源:网络整理
导读:我正在尝试在标签中显示SQL查询结果,但它没有显示.这是我的代码: string result = "SELECT ACTIVE FROM [dbo].[test] WHERE ID = '" + ID.Text + "' "; SqlCommand showresult = new SqlCommand(result,conn); conn.Open(); showresult.ExecuteNonQuery();
我正在尝试在标签中显示SQL查询结果,但它没有显示.这是我的代码:

string result = "SELECT ACTIVE FROM [dbo].[test] WHERE ID = '" + ID.Text + "' ";
     SqlCommand showresult = new SqlCommand(result,conn);
     conn.Open();
     showresult.ExecuteNonQuery();
     string actresult = ((string)showresult.ExecuteScalar());
     ResultLabel.Text = actresult;
     conn.Close();

需要帮助.谢谢!

解决方法

试试这个吧.

string result = "SELECT ACTIVE FROM [dbo].[test] WHERE ID = '" + ID.Text + "' ";
   SqlCommand showresult = new SqlCommand(result,conn);
   conn.Open();
   ResultLabel.Text = showresult.ExecuteScalar().ToString();
   conn.Close();

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读