.NET MySQL的参数化查询

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

 

转载于:https://www.cnblogs.com/xachary/p/3976908.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值