ExecuteNonQuery 
Executes a command that does not return rows. ExecuteDataset 
Executes a command that returns rows as a DataSet. ExecuteReader 
Executes a command that returns rows as a SqlDataReader. ExecuteScalar 
Executes a command that returns a single value as an object. 要这四个的使用方法,带参数的,我现在还搞不懂Command type这个参数怎么填如果有使用教程,那是最好,网上的普遍都没有ExecuteNonQuery的调用,以及详细的实例.

解决方案 »

  1.   

    Command type命今类型:一航为StoredProcedure(存储过程)和text(文本).
    例如1:ds = SqlHelper.ExecuteDataset(connection, CommandType.StoredProcedure, "sp_Type_AllList");
    connection:数据库连接
    CommandType.StoredProcedure:命令类型为存储过程.
    sp_Type_AllList:存储过程名称
    例如2:ds = SqlHelper.ExecuteDataset(connection, CommandType.text, "strsql");
    connection:数据库连接
    CommandType.text:命令类型为SQL语名.
    strsql:SQL语句如"select * from table1 "或"instert into ....."
      

  2.   

    一个用ExecuteNonQuery的调用"sp_Type_Delete"存储过程删除分类的例子:
    #region 删除网址分类信息函数
            public int Type_Delet(int TypeID)
            {
                //定义SqlConnection
                SqlConnection connection = null;
                int bRet = -1;
                try
                {
                    try
                    {
                        connection = SysConfig.GetConnection();//在SysConfig类中获取一个数据库连接
                    }
                    catch
                    {
                        return 1;//数据库连接异常
                    }
                    // 定义输入参数parameters
                    SqlParameter[] arParms = new SqlParameter[2];
                    // 传入参数
                    arParms[0] = new SqlParameter("@TypeID", SqlDbType.Int);  //分类ID
                    arParms[0].Value = TypeID;
                    //返回值"@RETURN_VALUE
                    arParms[1] = new SqlParameter("@RETURN_VALUE", SqlDbType.Int);
                    arParms[1].Direction = ParameterDirection.ReturnValue;
                    // 调用数据库访问函数
                    SqlHelper.ExecuteNonQuery(connection, CommandType.StoredProcedure, "sp_Type_Delete", arParms);
                    //bRet获取存储过程中的返回值"RETURN_VALUE
                    bRet = (int)arParms[1].Value;            }
                catch (Exception ex)
                {
                    string errMessage = "";
                    for (Exception tempException = ex; tempException != null; tempException = tempException.InnerException)
                    {
                        errMessage += tempException.Message + Environment.NewLine + Environment.NewLine;
                    }
                }
                finally
                {
                    if (connection != null)
                        connection.Dispose();
                }
                return bRet;
            }
            #endregion