码迷,mamicode.com
首页 > 数据库 > 详细

.NET MySQL的参数化查询

时间:2014-09-17 14:52:12      阅读:309      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   color   io   os   ar   div   sp   

MySqlConnection conn = new MySqlConnection(SqlConnnectString);

MySqlCommand cmd = new MySqlCommand("SELECT * FROM `TB_CM_Log` WHERE ID = ?ID LIMIT 1", conn);

cmd.Parameters.AddWithValue("ID", id);

cmd.CommandType = CommandType.Text;

cmd.Parameters.Clear();

TB_CM_Log model = new TB_CM_Log();

if (conn.State != ConnectionState.Open)
     conn.Open();

using (MySqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
{
      while (dr.Read())
      {
             model.ID = dr.GetString(0);
             model.ModType = dr.GetInt32(1);
             model.ModTypeName = dr.GetString(2);
             model.SourcesType = dr.GetString(3);
             model.Description = dr.GetString(4);
             model.OperatorID = dr.GetInt32(5);
             model.OperatorName = dr.GetString(6);
             model.SucFlag = dr.GetInt32(7);
             model.OperaTime = dr.GetDateTime(8);
             model.IP = dr.IsDBNull(9) ? "" : dr.GetString(9);
             model.ResultDes = dr.IsDBNull(10) ? "" : dr.GetString(10);
       }
}

conn.Close();

 

.NET MySQL的参数化查询

标签:des   style   blog   color   io   os   ar   div   sp   

原文地址:http://www.cnblogs.com/xachary/p/3976908.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!