日期:2014-05-17  浏览次数:21017 次

看一下我写的SqlHelper,好像有错误
本帖最后由 caozhy 于 2014-01-02 13:12:32 编辑
二楼上代码

------论坛禁止夹带广告,如再发现,就直接封杀了-----

------解决方案--------------------
第二个方法的返回类型直接改成DataSet,然后return返回值只留dataset,去掉.Tables[0]就可以了。
------解决方案--------------------
引用:
另外求大神告知  params SqlParameter[] parameters 这句话是什么意思?

SqlParameter[] parameters //参数化数组
params 加上之后就可以在不需要这个参数的时候直接不写。不加的话要写null

------解决方案--------------------
再加一个
public static DataSet ExecuteDataset(SqlConnection connection, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
        {
            //create a command and prepare it for execution
            SqlCommand cmd = new SqlCommand();
            PrepareCommand(cmd, connection, (SqlTransaction)null, commandType, commandText, commandParameters);

            //create the DataAdapter & DataSet
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();

            //fill the DataSet using default values for DataTable names, etc.
            da.Fill(ds);

            // detach the SqlParameters from the command object, so they can be used again.            
            cmd.Parameters.Clear();

            //return the dataset
            return ds;
        }