首页 ┆ 网站地图 ┆ 在线留言 ┆ 游戏资讯 ┆ 资源下载 ┆ 端午节祝福 ┆ 迅雷在线影视 ┆淘宝手机在线充值 ┆淘宝游戏点卡充值 
设为首页
加入收藏
联系我们
高级搜索
您当前的位置: 主页>NET专区>ASP.NET>asp.net操作3种类型存储过程,附dataset 与XML操作
asp.net操作3种类型存储过程,附dataset 与XML操作
来源: 发布时间:2007-12-19 发布人: 浏览: 人次   字体: [ ]  

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中使用Ajax
·asp.net(C#)上传下载及文件管理代码...
·asp.net操作xml文件的代码实例
·ASP.NET程序开发中经典常用的三十三...
·asp.net生成缩略图代码实例(可按百...
·在ASP.NET中实现跨页面多选的代码
·asp.net实现url传递中文的解决方案
·asp.net使用checkbox控制datagrid行...
·asp.net操作Excel,读取、导出,操作...
·asp.net页面回传与js调用服务端事件...
 §最新评论:(评论内容只代表网友观点,与本站立场无关!)
网名: 验证码:  【所有评论】【↑返回顶部
评 分: 12 345
评论内容:(不能超过500字,请自觉遵守互联网相关政策法规。[按 Ctrl+Enter 可直接提交]
注意:请勿在本站发布政治话题、色情及违反法律的内容。
IT知道网 声明:刊登此文章是为了传递更多信息,文章内容仅供参考,转载请注明出处。
推 荐 文 章
·实例讲解ASP.NET实现加密Cook...
·如何实现在DataList控件中的D...
·实例讲解asp.net生成高质量缩
·asp.net适用于IE或FireFox的...
·举例详解C#代码与javaScript...
·asp.net无刷新上传文件
·在Ie中保存图片时出现"800700...
·asp.net文件上传大小限制的控
·asp.net动态生成txt文本文件...
·asp.net实现将Excel文件导入...
·实现多列,带图片的DropDownLi...
·javascript实现TreeView 控件
·ASP.NET配置Word的操作权限
·让FileUpload控件在IE和FireF...
·ASP.NET实现Office文档的分类
热 门 文 章
·asp.net(C#)上传下载及文件管...
·图解asp.net如何用excel做报...
·asp.net无刷新上传文件
·Asp.Net防止刷新重复提交数据...
·asp.net实现将Excel文件导入...
·ASP.NET取得物理路径和虚拟路...
·asp.net中Web.Config配置文件...
·asp.net(c#)生成验证码代码,...
·asp.net页面回传与js调用服务...
·asp.net中DataBinder.Eval的...
·asp.net(C#版)实现登录验证码...
·DataGrid中DropDownList触发S...
·asp.net可输入的下拉框复合控...
·ASP.net 实现批量数据更新或...
·asp.net中常见的几种日历控件...
网站首页 - 关于本站 - 加入收藏 - 网站地图 - 友情连接 - 在线留言 - 联系我们 - 返回顶部
Copyright © 2007 IT知道网.[冀ICP备07026896号]. All Rights Reserved .