asp.net使用3中类型存储过程

public static SqlConnection creatString()//创建连接字符串
    {
        string mystring = "Data Source=5FAF81B03F644F7//FGFDS;Initial Catalog=wujilin;User ID=sa;Password=222222";

        SqlConnection myconnection = new SqlConnection(mystring);

        return myconnection;
   }

    public static DataSet givemessage()//无参数 返回一个集合
    {
        DataSet ds = new DataSet();
        SqlConnection myconnecting =DB.creatString();
        SqlDataAdapter sdr = new SqlDataAdapter("givemessage", myconnecting);
        sdr.SelectCommand.CommandType = CommandType.StoredProcedure;
        sdr.Fill(ds);

        return ds;
    }
    public static DataSet givemessage1(string a)//带输入参数 返回序列集合
    {
        SqlParameter workParam1 = new SqlParameter("@password", SqlDbType.NChar);
        workParam1.Direction = ParameterDirection.Input;
        workParam1.Value = a;

        SqlDataAdapter sdr = new SqlDataAdapter();
        sdr.SelectCommand = new SqlCommand();

        sdr.SelectCommand.Connection = DB.creatString();
        sdr.SelectCommand.CommandText = "messagexyz";
        sdr.SelectCommand.CommandType = CommandType.StoredProcedure;
        sdr.SelectCommand.Parameters.Add(workParam1);

        DataSet ds = new DataSet();
        sdr.Fill(ds);
        return ds;
    }

    public static string singerValue(string m)//返回一个值
    {
        SqlConnection conn = DB.creatString();
        SqlCommand mycommand = new SqlCommand("number", conn);
        mycommand.CommandType = CommandType.StoredProcedure;

        SqlParameter workParam;          //输入参数
        workParam = new SqlParameter("@password", SqlDbType.NChar);
        workParam.Direction = ParameterDirection.Input;
        workParam.Value = m;
        mycommand.Parameters.Add(workParam);

        workParam = new SqlParameter("@ItemCount", SqlDbType.Int);//输出参数
        workParam.Direction = ParameterDirection.Output;
        mycommand.Parameters.Add(workParam);

        conn.Open();
        mycommand.ExecuteNonQuery();
        conn.Close();

        return mycommand.Parameters["@ItemCount"].Value.ToString();
    }
}
 

dataset 与XML

 protected void Button3_Click(object sender, EventArgs e)
    {
        DataSet ds = new DataSet();
        SqlConnection conn = DB.creatString();
        SqlDataAdapter sdr = new SqlDataAdapter("select * from test", conn);
        sdr.Fill(ds);
        ds.WriteXml(Server.MapPath("test.xml")); //将数据写入xml文件
    }
    protected void Button4_Click(object sender, EventArgs e)
    {
        DataSet ds = new DataSet();
        ds.ReadXml(Server.MapPath("test.xml"));//从xml文件中读取数据
        this.GridView1.DataSource = ds;
        this.GridView1.DataBind();
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值