现在位置:首页->技术中心->.NET
asp.net使用3中类型存储过程
作者: 日期: 2007-12-18 20:38:41 访问次数:出处:
 显示选项:自动滚屏[左键停止]
 

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();
    }

⊕相关文章
  • ·ASP.NET 2.0 本地化技术之研究(二)
  • ·ASP.NET 2.0 本地化技术之研究(1)
  • ·使用LINQ to SQL (第一部分)(韩现龙译)
  • ·解析:如何在 ASP.NET 中下载文件
  • ·在 .NET 框架程序中通过DllImport使用 Win32 API
  • ·ASP.NET2.0中login控件的一点整理