Today, when Liu checked my program, he found that I had made a very low-level error. I wrote it out today and told myself not to make the same mistake again in the future...
When you add a shift, you may encounter this locking situation. When I added a shift, I did not carefully read the code in the DAL. I simply read the method and made a very low-level mistake. To prevent errors.
Two solutions are available:
1. Do not deadlock. Choose to check whether the deadlock can be added correctly before deadlock.
2. query the data in the database directly after adding the database. When adding or editing a file, you must check it in the library. This is the most direct and effective method.
Remember not to make the same mistake again in the future .....
# Region initialization parameters
/// <Summary>
/// Initialization parameters
/// </Summary>
/// <Returns> System. Collections. ArrayList </returns>
Private ArrayList InitlizeParames (ClassInfo ci, DataOperationType type)
{
ArrayList parames = new ArrayList ();
// Delete
If (type = DataOperationType. DEL)
{
ExIDbDataParameter parame1 = new ExIDbDataParameter ("COLUMN1", DbType. Int64, ci. Id );
Parames. Add (parame1 );
Return parames;
}
// Modify
If (type = DataOperationType. UPDATE)
{
ExIDbDataParameter parame1 = new ExIDbDataParameter ("COLUMN1", DbType. Int64, ci. Id );
Parames. Add (parame1 );
}
// Modify and add
Parames. Add (parame17 );
ExIDbDataParameter parame24 = new ExIDbDataParameter ("COLUMN24", DbType. DateTime, ci. EditZzDate );
Parames. Add (parame24 );
ExIDbDataParameter parame25 = new ExIDbDataParameter ("COLUMN25", DbType. DateTime, ci. EditZzEndDate );
Parames. Add (parame25 );
ExIDbDataParameter parame26 = new ExIDbDataParameter ("COLUMN26", DbType. Int32, ci. ClassChuShi); // records the room, which has a default value.
Parames. Add (parame26 );
ExIDbDataParameter parame27 = new ExIDbDataParameter ("COLUMN27", DbType. Int32, ci. ClassJXState );
Parames. Add (parame31 );
Parames. Add (parame38 );
Return parames;
}
# Endregion initialization parameters
# Add a class to region
/// <Summary>
/// Add the class information and return the ID
/// </Summary>
/// <Param name = "ci"> JW. Module. ClassInfo object </param>
/// <Returns> ID returned for success and 0 returned for failure </returns>
Public int AddClassInfo (ClassInfo ci)
{
Int id = 0;
String strSql = "insert into Table2 ("
+ "COLUMN2, COLUMN3, COLUMN4, COLUMN5, COLUMN6, COLUMN7, COLUMN8, COLUMN10, COLUMN11, COLUMN12, COLUMN13, COLUMN14, COLUMN15, COLUMN16, COLUMN17, COLUMN18 ,"
+ "COLUMN19, COLUMN20, COLUMN21, COLUMN22, COLUMN23, COLUMN24, COLUMN25, COLUMN26, COLUMN27, COLUMN28, COLUMN29, COLUMN30, COLUMN31, COLUMN32, COLUMN33, COLUMN34 ,"
+ "COLUMN35, COLUMN36, COLUMN37, COLUMN38 )"
+ "VALUES ("
+ "@ COLUMN2, @ COLUMN3, @ COLUMN4, @ COLUMN5, @ COLUMN6, @ COLUMN7, @ COLUMN8, @ COLUMN12, @ COLUMN10, @ COLUMN11, @ COLUMN12, @ COLUMN13, @ COLUMN14, @ COLUMN15, @ COLUMN16 ,"
+ "@ COLUMN17, @ COLUMN18, @ COLUMN19, @ COLUMN20, @ COLUMN21, @ COLUMN22, @ COLUMN23, @ COLUMN24, @ COLUMN25, @ COLUMN26, @ COLUMN27, @ COLUMN28, @ COLUMN29, @ COLUMN30 ,"
+ "@ COLUMN31, @ COLUMN32, @ COLUMN33, @ COLUMN34, @ COLUMN35, @ COLUMN36, @ COLUMN37, @ COLUMN38) select @ identity ";
ArrayList parames = this. InitlizeParames (ci, DataOperationType. ADD );
Try
{
Id = int. Parse (dataHelper. ExecuteScalar (strSql, CommandType. Text, parames). ToString ());
}
Catch
{
Id = 0;
}
Return id;
}
# Add an endregion class
Perception:
1. When writing something, you must first think about how to write it.
2. Be sure to take full control of the program, not just the methods you use. Comprehensive control is required.
3. Although this error is small, it is very low-level. I can't underestimate this error. I must take this as a precaution. Never make similar mistakes again!
4. Do not just look at what you can see on the surface, but also look at what else you need to do with this module.
5. Try it as a user at all times and think about it for your future use. If you do well, it is easy to use.
Author Wang Hong-hong