c#

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);
        }


转载于:https://www.cnblogs.com/zzzili/p/6662539.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值