• 自己写的SqlHelper,提示在调用"Fill"前,SelectCommand 属性尚未初始化.错误



    namespace 操作数据
    {
        class SqlHelper
        {
            public DataSet SqlTODs(string cmdstring)
            {
                DataSet ds = new DataSet();
                try
                {
                    string sqlstring = System.Configuration.ConfigurationManager.ConnectionStrings["dbStr"].ConnectionString;
                    using (SqlConnection conn = new SqlConnection(sqlstring))
                    {
                        conn.Open();
                        //string cmd = cmdstring;
                        SqlCommand cmd = conn.CreateCommand();
                        cmd.CommandText = cmdstring;
                        SqlDataAdapter da = new SqlDataAdapter();
                        da.Fill(ds);
                        return ds;
                    }
                }
                catch(Exception ex)
                {
                    MessageBox.Show("错误信息为:  " + ex.Message);
                    return ds;
                }
              
            }
        }
    }

    原因是:没有给SqlDataAdapter传递参数  ,

  • 相关阅读:
    二项分布和多项分布
    TF-IDF学习笔记(二)
    TF-IDF学习笔记(一)
    jieba中文分词
    爬虫利器3:Xpath语法与lxml库
    Python爬虫利器1:Requests库的用法
    Python爬虫实战一之爬取糗事百科段子
    Python中的逻辑运算符
    Python:闭包函数与装饰器
    Python:函数名称空间与作用域:
  • 原文地址:https://www.cnblogs.com/xiaoqisfzh/p/4160557.html
Copyright © 2020-2023  润新知