人法地,地法天,天法道,道法自然
分类:
2009-10-14 18:42:08
<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
}