首页 新闻 会员 周边

求助 关于 本机框架位于堆栈顶部,因此无法计算表达式的值

0
悬赏园豆:50 [已解决问题] 解决于 2015-03-30 11:04

程序是点击屏幕上的按钮 返回数据库中MyClass表中数据的个数

代码如下:

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string sql = "select count(*) from MyStudent";

            MessageBox.Show(SqlHelper.ExecuteScalar(sql, CommandType.Text).ToString());
        }
    }

 



其中SqlHelper是一个操作数据库的静态类,代码如下:

public static class SqlHelper
    {
        private static string conStr = ConfigurationManager.ConnectionStrings["Coco"].ConnectionString;
 public static object ExecuteScalar(string sqlStr, CommandType ct, params SqlParameter[] sq)
        {
            using (SqlConnection sqlCon = new SqlConnection(conStr))
            {
                using (SqlCommand cmd = new SqlCommand(sqlStr, sqlCon))
                {
                    cmd.CommandType = ct;
                    if (sq != null)
                    {
                        cmd.Parameters.AddRange(sq);
                    }
                    //打开连接
                    sqlCon.Open();
                    return cmd.ExecuteScalar();
                }
            }
        }
}

 



连接字符串如下:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>

  <connectionStrings>
    <add name="Coco" connectionString="Data Source=.;Initial Catalog=T_Seat;Integrated Security=True"/>
  </connectionStrings>
</configuration>

 

运行后,点击按钮后,查看错误信息,如下:

爬虫北京的主页 爬虫北京 | 初学一级 | 园豆:159
提问于:2015-03-24 10:57
< >
分享
最佳答案
0

将自己的ip重置下就好了

爬虫北京 | 初学一级 |园豆:159 | 2015-03-25 09:22
其他回答(1)
0

用debug模式,不要用Release,如下图:

收获园豆:50
hexllo | 园豆:318 (菜鸟二级) | 2015-03-25 15:05

我使用debug模式的,我是用数据库管理软件把ip重置为127.0.0.1后就好了。

支持(0) 反对(0) 爬虫北京 | 园豆:159 (初学一级) | 2015-03-25 20:39

@爬虫北京: 好样的。

支持(0) 反对(0) hexllo | 园豆:318 (菜鸟二级) | 2015-03-30 10:18
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册