62,052
社区成员
发帖
与我相关
我的任务
分享
MySqlConnection myConnection = new MySqlConnection("Database=xbxx;Data Source=localhost;User Id=root;Password=baobaowawa");
MySqlCommand myCommand = new MySqlCommand(query, myConnection);
myCommand.Connection = myConnection;
myConnection.Open();
MySqlDataReader myReader;
myReader = myCommand.ExecuteReader();
<appSettings/>
<connectionStrings>
<add name="Connection" connectionString="Data Source=localhost; Database=xbxx;User ID=root;Password=baobaowawa;Port=3306" />
</connectionStrings>
MySqlConnection oMySqlConn = new MySqlConnection();
oMySqlConn.ConnectionString = "";
string query = "select * from cool_content";
//MySqlConnection myConnection = new MySqlConnection("Database=xbxx;Data Source=localhost;User Id=root;Password=baobaowawa");
MySqlCommand myCommand = new MySqlCommand(query, oMySqlConn);
myCommand.Connection = oMySqlConn;
//myConnection.Open();
oMySqlConn.Open();
MySqlDataReader myReader = myCommand.ExecuteReader();
<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
}
<connectionStrings>
<add name="Connection String" connectionString="server=localhost;database=xbxx;uid=sa;pwd=123456"
providerName="System.Data.SqlClient" />
</connectionStrings>