少一个逗号出的错误
Code
1 /// <summary>
2 /// 更新一条数据
3 /// </summary>
4 public void Update()
5 {
6 StringBuilder strSql = new StringBuilder();
7 strSql.Append("update T_Ryzhzhxx set ");
8 strSql.Append("CardNo=@CardNo,");
9 strSql.Append("ChgNo=@ChgNo,");
10 //strSql.Append("Chjrq=@Chjrq,");
11 //strSql.Append("Dzzhjbsh=@Dzzhjbsh,");
12 ///strSql.Append("Dzzhjchchjdbh=@Dzzhjchchjdbh,");
13 //strSql.Append("Dzzhjchcrchrq=@Dzzhjchcrchrq,");
14 //strSql.Append("Dzzhjmchjdbh=@Dzzhjmchjdbh,");
15 //strSql.Append("Dzzhjmcrchrq=@Dzzhjmcrchrq,");
16 strSql.Append("GameNo=@GameNo,");
17 strSql.Append("HdNo=@HdNo,");
18 //strSql.Append("RecTime=@RecTime,");
19 //strSql.Append("Ryid=@Ryid,");
20 //strSql.Append("Ryzhzhid=@Ryzhzhid,");
21 strSql.Append("SfNo=@SfNo,");
22 strSql.Append("Shbdw=@Shbdw,");
23 //strSql.Append("SPR=@SPR,");
24 //strSql.Append("SPSJ=@SPSJ,");
25 strSql.Append("State=@State,");
26 //strSql.Append("UpTime=@UpTime,");
27 //strSql.Append("Zhjffrq=@Zhjffrq,");
28 //strSql.Append("Zhjshbllr=@Zhjshbllr,");
29 //strSql.Append("Zhjshbrlxfsh=@Zhjshbrlxfsh,");
30 //strSql.Append("Zhjshbrq=@Zhjshbrq,");
31 //strSql.Append("Zhjyxqjzhrq=@Zhjyxqjzhrq,");
32 //strSql.Append("Zhjyxqkshrq=@Zhjyxqkshrq,");
33 //strSql.Append("Zhjzhzwchrq=@Zhjzhzwchrq,");
34 strSql.Append("SfRemark=@SfRemark,");
35 strSql.Append("SQNo=@SQNo");
36 strSql.Append("Rylb=@Rylb");
37 strSql.Append(" where Ryzhzhid=@Ryzhzhid ");
38 OleDbParameter[] parameters = {
39 new OleDbParameter("@CardNo", OleDbType.VarChar,20),
40 new OleDbParameter("@ChgNo", OleDbType.VarChar,20),
41 //new OleDbParameter("@Chjrq", OleDbType.Date),
42 //new OleDbParameter("@Dzzhjbsh", OleDbType.VarChar,50),
43 //new OleDbParameter("@Dzzhjchchjdbh", OleDbType.VarChar,50),
44 //new OleDbParameter("@Dzzhjchcrchrq", OleDbType.Date),
45 //new OleDbParameter("@Dzzhjmchjdbh", OleDbType.VarChar,50),
46 //new OleDbParameter("@Dzzhjmcrchrq", OleDbType.Date),
47 new OleDbParameter("@GameNo", OleDbType.VarChar,20),
48 new OleDbParameter("@HdNo", OleDbType.VarChar,20),
49 //new OleDbParameter("@RecTime", OleDbType.Date),
50 //new OleDbParameter("@Ryid", OleDbType.VarChar,36),
51 new OleDbParameter("@SfNo", OleDbType.VarChar,20),
52 new OleDbParameter("@Shbdw", OleDbType.VarChar,20),
53 //new OleDbParameter("@SPR", OleDbType.VarChar,20),
54 //new OleDbParameter("@SPSJ", OleDbType.Date),
55 new OleDbParameter("@State", OleDbType.VarChar,20),
56 //new OleDbParameter("@UpTime", OleDbType.Date),
57 //new OleDbParameter("@Zhjffrq", OleDbType.Date),
58 //new OleDbParameter("@Zhjshbllr", OleDbType.VarChar,50),
59 //new OleDbParameter("@Zhjshbrlxfsh", OleDbType.VarChar,200),
60 //new OleDbParameter("@Zhjshbrq", OleDbType.Date),
61 //new OleDbParameter("@Zhjyxqjzhrq", OleDbType.Date),
62 //new OleDbParameter("@Zhjyxqkshrq", OleDbType.Date),
63 //new OleDbParameter("@Zhjzhzwchrq", OleDbType.Date),
64 new OleDbParameter("@SfRemark",OleDbType.VarChar,200),
65 new OleDbParameter("@SQNo",OleDbType.VarChar,20),
66 new OleDbParameter("@Rylb", OleDbType.VarChar,20),
67 new OleDbParameter("@Ryzhzhid", OleDbType.VarChar,36)
68 };
69 parameters[0].Value = CardNo;
70 parameters[1].Value = ChgNo;
71 //parameters[2].Value = Chjrq;
72 //parameters[3].Value = Dzzhjbsh;
73 //parameters[4].Value = Dzzhjchchjdbh;
74 //parameters[5].Value = Dzzhjchcrchrq;
75 //parameters[6].Value = Dzzhjmchjdbh;
76 //parameters[7].Value = Dzzhjmcrchrq;
77 parameters[2].Value = GameNo;
78 parameters[3].Value = HdNo;
79 //parameters[10].Value = RecTime;
80 //parameters[11].Value = Ryid;
81 parameters[4].Value = SfNo;
82 parameters[5].Value = Shbdw;
83 //parameters[14].Value = SPR;
84 //parameters[15].Value = SPSJ;
85 parameters[6].Value = State;
86 //parameters[17].Value = UpTime;
87 //parameters[18].Value = Zhjffrq;
88 //parameters[19].Value = Zhjshbllr;
89 //parameters[20].Value = Zhjshbrlxfsh;
90 //parameters[21].Value = Zhjshbrq;
91 //parameters[22].Value = Zhjyxqjzhrq;
92 //parameters[23].Value = Zhjyxqkshrq;
93 //parameters[24].Value = Zhjzhzwchrq;
94 parameters[7].Value = SfRemark;
95 parameters[8].Value = SQNo;
96 parameters[9].Value = Rylb;
97 parameters[10].Value = Ryzhzhid;
98
99 OleDbHelper.ExecuteNonQuery(CommandType.Text, strSql.ToString(), parameters);
100 }
表的Rylb列是后来加上,再改方法时,行35少了一个逗号,程序运行没有错误,但是出现数据错误。1 /// <summary>
2 /// 更新一条数据
3 /// </summary>
4 public void Update()
5 {
6 StringBuilder strSql = new StringBuilder();
7 strSql.Append("update T_Ryzhzhxx set ");
8 strSql.Append("CardNo=@CardNo,");
9 strSql.Append("ChgNo=@ChgNo,");
10 //strSql.Append("Chjrq=@Chjrq,");
11 //strSql.Append("Dzzhjbsh=@Dzzhjbsh,");
12 ///strSql.Append("Dzzhjchchjdbh=@Dzzhjchchjdbh,");
13 //strSql.Append("Dzzhjchcrchrq=@Dzzhjchcrchrq,");
14 //strSql.Append("Dzzhjmchjdbh=@Dzzhjmchjdbh,");
15 //strSql.Append("Dzzhjmcrchrq=@Dzzhjmcrchrq,");
16 strSql.Append("GameNo=@GameNo,");
17 strSql.Append("HdNo=@HdNo,");
18 //strSql.Append("RecTime=@RecTime,");
19 //strSql.Append("Ryid=@Ryid,");
20 //strSql.Append("Ryzhzhid=@Ryzhzhid,");
21 strSql.Append("SfNo=@SfNo,");
22 strSql.Append("Shbdw=@Shbdw,");
23 //strSql.Append("SPR=@SPR,");
24 //strSql.Append("SPSJ=@SPSJ,");
25 strSql.Append("State=@State,");
26 //strSql.Append("UpTime=@UpTime,");
27 //strSql.Append("Zhjffrq=@Zhjffrq,");
28 //strSql.Append("Zhjshbllr=@Zhjshbllr,");
29 //strSql.Append("Zhjshbrlxfsh=@Zhjshbrlxfsh,");
30 //strSql.Append("Zhjshbrq=@Zhjshbrq,");
31 //strSql.Append("Zhjyxqjzhrq=@Zhjyxqjzhrq,");
32 //strSql.Append("Zhjyxqkshrq=@Zhjyxqkshrq,");
33 //strSql.Append("Zhjzhzwchrq=@Zhjzhzwchrq,");
34 strSql.Append("SfRemark=@SfRemark,");
35 strSql.Append("SQNo=@SQNo");
36 strSql.Append("Rylb=@Rylb");
37 strSql.Append(" where Ryzhzhid=@Ryzhzhid ");
38 OleDbParameter[] parameters = {
39 new OleDbParameter("@CardNo", OleDbType.VarChar,20),
40 new OleDbParameter("@ChgNo", OleDbType.VarChar,20),
41 //new OleDbParameter("@Chjrq", OleDbType.Date),
42 //new OleDbParameter("@Dzzhjbsh", OleDbType.VarChar,50),
43 //new OleDbParameter("@Dzzhjchchjdbh", OleDbType.VarChar,50),
44 //new OleDbParameter("@Dzzhjchcrchrq", OleDbType.Date),
45 //new OleDbParameter("@Dzzhjmchjdbh", OleDbType.VarChar,50),
46 //new OleDbParameter("@Dzzhjmcrchrq", OleDbType.Date),
47 new OleDbParameter("@GameNo", OleDbType.VarChar,20),
48 new OleDbParameter("@HdNo", OleDbType.VarChar,20),
49 //new OleDbParameter("@RecTime", OleDbType.Date),
50 //new OleDbParameter("@Ryid", OleDbType.VarChar,36),
51 new OleDbParameter("@SfNo", OleDbType.VarChar,20),
52 new OleDbParameter("@Shbdw", OleDbType.VarChar,20),
53 //new OleDbParameter("@SPR", OleDbType.VarChar,20),
54 //new OleDbParameter("@SPSJ", OleDbType.Date),
55 new OleDbParameter("@State", OleDbType.VarChar,20),
56 //new OleDbParameter("@UpTime", OleDbType.Date),
57 //new OleDbParameter("@Zhjffrq", OleDbType.Date),
58 //new OleDbParameter("@Zhjshbllr", OleDbType.VarChar,50),
59 //new OleDbParameter("@Zhjshbrlxfsh", OleDbType.VarChar,200),
60 //new OleDbParameter("@Zhjshbrq", OleDbType.Date),
61 //new OleDbParameter("@Zhjyxqjzhrq", OleDbType.Date),
62 //new OleDbParameter("@Zhjyxqkshrq", OleDbType.Date),
63 //new OleDbParameter("@Zhjzhzwchrq", OleDbType.Date),
64 new OleDbParameter("@SfRemark",OleDbType.VarChar,200),
65 new OleDbParameter("@SQNo",OleDbType.VarChar,20),
66 new OleDbParameter("@Rylb", OleDbType.VarChar,20),
67 new OleDbParameter("@Ryzhzhid", OleDbType.VarChar,36)
68 };
69 parameters[0].Value = CardNo;
70 parameters[1].Value = ChgNo;
71 //parameters[2].Value = Chjrq;
72 //parameters[3].Value = Dzzhjbsh;
73 //parameters[4].Value = Dzzhjchchjdbh;
74 //parameters[5].Value = Dzzhjchcrchrq;
75 //parameters[6].Value = Dzzhjmchjdbh;
76 //parameters[7].Value = Dzzhjmcrchrq;
77 parameters[2].Value = GameNo;
78 parameters[3].Value = HdNo;
79 //parameters[10].Value = RecTime;
80 //parameters[11].Value = Ryid;
81 parameters[4].Value = SfNo;
82 parameters[5].Value = Shbdw;
83 //parameters[14].Value = SPR;
84 //parameters[15].Value = SPSJ;
85 parameters[6].Value = State;
86 //parameters[17].Value = UpTime;
87 //parameters[18].Value = Zhjffrq;
88 //parameters[19].Value = Zhjshbllr;
89 //parameters[20].Value = Zhjshbrlxfsh;
90 //parameters[21].Value = Zhjshbrq;
91 //parameters[22].Value = Zhjyxqjzhrq;
92 //parameters[23].Value = Zhjyxqkshrq;
93 //parameters[24].Value = Zhjzhzwchrq;
94 parameters[7].Value = SfRemark;
95 parameters[8].Value = SQNo;
96 parameters[9].Value = Rylb;
97 parameters[10].Value = Ryzhzhid;
98
99 OleDbHelper.ExecuteNonQuery(CommandType.Text, strSql.ToString(), parameters);
100 }
原来生成了sql语句如下:
update T_Ryzhzhxx set CardNo=@CardNo,ChgNo=@ChgNo,GameNo=@GameNo,HdNo=@HdNo,SfNo=@SfNo,Shbdw=@Shbdw,State=@State,SfRemark=@SfRemark,SQNo=@SQNoRylb=@Rylb where Ryzhzhid=@Ryzhzhid
于是字段SQNO中为0;@SQNoRylb=@Rylb当两个参数值不等时,SQNo=0了。再加上OleDB不是按参数名来加载参数值,而是按参数顺序。就出现错误的数据