Chinaunix首页 | 论坛 | 博客
  • 博客访问: 720972
  • 博文数量: 158
  • 博客积分: 6010
  • 博客等级: 准将
  • 技术积分: 1643
  • 用 户 组: 普通用户
  • 注册时间: 2007-10-11 14:37
个人简介

人法地,地法天,天法道,道法自然

文章分类

全部博文(158)

文章存档

2022年(1)

2020年(3)

2016年(1)

2014年(7)

2013年(4)

2010年(5)

2009年(86)

2008年(25)

2007年(26)

我的朋友

分类:

2009-10-14 18:42:08

web.config下设置:
 

<appSettings>

    <add key="Mysqlstudb" value="User Id=root;Host=localhost;Database=studb;Password=root;Port=3307"/>   

    <add key="FCKeditor:BasePath" value="~/FCKeditor/"/>

    <add key="FCKeditor:UserFilesPath" value="~/image"/>  

appSettings>

 
查询调用存储过程:
 

using System;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

 

using MySql.Data.MySqlClient; 

 

    private MySqlCommand mycomm;

    private MySqlDataReader dr;

    private string strconn = ConfigurationManager.AppSettings["Mysqlstudb"];

    private MySqlConnection myco;

    protected void Page_Load(object sender, EventArgs e)

    {

        if (!IsPostBack)

        {

          //  string sql = "select kind_id,kind_name from kind where kind_type='notice'";//新闻,通知,公告类

            myco = new MySqlConnection(strconn);

            myco.Open();

 

           // mycomm = new MySqlCommand(sql, myco);

            mycomm = new MySqlCommand("kind_pro",myco);

            mycomm.CommandType = CommandType.StoredProcedure;

            mycomm.Parameters.Add("@kind_type", "notice");

            dr = mycomm.ExecuteReader();

            while (dr.Read())

            {

                kind_id.Items.Add(new ListItem(dr["kind_name"].ToString(), dr["kind_id"].ToString()));

 

            }

          //  kind_id.SelectedIndexChanged += new EventHandler(kind_id_SelectedIndexChanged);

            mycomm.Dispose();

            dr.Dispose();

            myco.Close();

            create_date.Text = System.DateTime.Now.Date.ToShortDateString();

            create_time.Text = System.DateTime.Now.ToString();

        }

       

    }

 

写入数据调用存储过程:

 

protected void News_ADD_bt_Click(object sender, EventArgs e)

    {

        myco = new MySqlConnection(strconn);

        myco.Open();

        mycomm = new MySqlCommand("notice_add_pro", myco);

        mycomm.CommandType = CommandType.StoredProcedure;

        mycomm.Parameters.Add("@idnam", idnam.Text);

        mycomm.Parameters.Add("@content", FCKeditor1.Value);

        mycomm.Parameters.Add("@create_date", create_date.Text);

        mycomm.Parameters.Add("@create_time", create_time.Text);

        mycomm.Parameters.Add("@from_where", from_where.Text);

        mycomm.Parameters.Add("@iduse", "mayeping");

        mycomm.Parameters.Add("@kind_id", kind_id.SelectedValue);

 

        mycomm.ExecuteNonQuery();

        mycomm.Dispose();

        myco.Close();

 

        idnam.Text = "";

        FCKeditor1.Value = "";

        create_date.Text = System.DateTime.Now.Date.ToShortDateString();

        create_time.Text = System.DateTime.Now.ToString();

 

        //idnam,content,create_date,create_time,from_where,iduse,kind_id

    }

 

 

阅读(3822) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~