1.MySql连接
<connectionStrings>
<add name="mysql" connectionString="server=localhost;port=3306;user id=zzzili;password=zzzili123;database=zzzili;CharSet=gb2312;" providerName="MySql.Data.MySqlClient"/>
</connectionStrings>
private string mysqlYunfeng = System.Configuration.ConfigurationManager.ConnectionStrings["mysql"].ConnectionString;
2.数据操作
using (MySqlDataReader dr = MySqlHelper.ExecuteReader(mysqlYunfeng, sql))
{
if (dr.HasRows == true)
{
while (dr.Read())
{
if (dr[0].ToString() == "Logo")
{
node.LogoVersion = dr[1].ToString();
}
else if (dr[0].ToString() == "City")
{
node.CityVersion = dr[1].ToString();
}
}
}
}
MySqlParameter[] paras = new MySqlParameter[4];
paras[0] = new MySqlParameter("@stuNum",stuNum);
paras[1] = new MySqlParameter("@answer",answer);
paras[2] = new MySqlParameter("@score",score);
paras[3] = new MySqlParameter("@exid",ex_id);
3.Json序列化
//JavaScriptSerializer类在System.Web.Extensions.dll中,注意添加这个引用
JavaScriptSerializer serializer = new JavaScriptSerializer();
//JSON序列化
string result = serializer.Serialize(node);
4.Request.QueryString[""].ToString();
5.输出调试信息
System.Diagnostics.Debug.WriteLine(returnStr);
6.sql中的判断
select case when a>b then a when b>c then b esle c end from table_name where ...
7.web Table写入Excel
protected void Button1_Click(object sender, EventArgs e)
{
BndTableList(this.txtTime.Text, null);
StringBuilder tstr = new StringBuilder();
foreach (TableRow row in Table1.Rows)
{
foreach (TableCell cell in row.Cells)
{
tstr.AppendFormat("{0} ",cell.Text);
}
tstr.Append("\r\n");
}
WriteFile(tstr.ToString());
}
private void WriteFile(string str)
{
System.IO.File.WriteAllText("C:\\upload\\aaa.xls", str, Encoding.UTF8);
}