Mysqlconnection conn =Newmysqlconnection (sqlconnnectstring); Mysqlcommand cmd=NewMysqlcommand ("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=NewTb_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 (Ten) ?"": Dr. GetString (Ten); }}conn. Close ();
parameterized queries for. NET MySQL