这是我第一次进入MySQL世界。但是,我收到了这个错误。
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' '9/30/2012 12:00:00 AM', '10/1/2012 12:00:00 AM', '9/30/2012 12:00:00 AM', '', ' at line 1
命令文本很长,所以很抱歉。另外,我知道关于SQL注入以及如何预防它;但是,这个程序仅供内部使用,不会冒这个风险。
foreach (DataRow r in dt.Rows)
{
cmd = connection.CreateCommand();
cmd.CommandText = "INSERT INTO `" + TableName + "`";
cmd.CommandText += "(ControlNumber, Jur_ID, Jur_Status, Jur_Collected, 1Jur_Yr, 1Jur_Install, 1Jur_Amt, 1Jur_Paid, 1Jur_Due, 1Jur_DtDue, 1Jur_FinalDue, 1Jur_DtPaid, 1Jur_Thru, ";
cmd.CommandText += "2Jur_Yr, 2Jur_Install, 2Jur_Amt, 2Jur_Paid, 2Jur_Due, 2Jur_DtDue, 2Jur_FinalDue, 2Jur_DtPaid, 2Jur_Thru, 3Jur_Yr, 3Jur_Install, 3Jur_Amt, 3Jur_Paid, 3Jur_Due, 3Jur_DtDue, 3Jur_FinalDue, 3Jur_DtPaid, 3Jur_Thru, ";
cmd.CommandText += "4Jur_Yr, 4Jur_Install, 4Jur_Amt, 4Jur_Paid, 4Jur_Due, 4Jur_DtDue, 4Jur_FinalDue, 4Jur_DtPaid, 4Jur_Thru, Jur_PayNotes, Jur_OtherNotes, MillageRate, AssessedValue, LandValue, ImprovedValue, TotalValue, ";
cmd.CommandText += "1Jur_DelAmount, 2Jur_DelAmount, 3Jur_DelAmount, 4Jur_DelAmount, Unincorporated, Ex_Homestead, Ex_Disabled, Ex_Veteran, Ex_Mortgage, Ex_Star, Ex_Elderly, Ex_Other, 1Jur_Del, 2Jur_Del, 3Jur_Del, 4Jur_Del, ";
cmd.CommandText += "DelVerifiedBy, MilNextDue, DelOverideNotes, SpokeTo, LumpSum, SchoolTax, PriorYearDel, 1Jur_Partial, 2Jur_Partial, 3Jur_Partial, 4Jur_Partial, 1Jur_Timely, 2Jur_Timely, 3Jur_Timely, 4Jur_Timely, ";
cmd.CommandText += "1Jur_FrDue, 2Jur_FrDue, 3Jur_FrDue, 4Jur_FrDue, LowestDiscount, PaidDiscount, NoDiscount, PrimaryAuth, OtherAuth, MultiParcel, LandImprov, PriorYearDelq, AnyRedeemed, SpecialAssess, AnyExemptions, ";
cmd.CommandText += "NextYearAssessment, LastYearPaid, TaxSale, TaxRateArea, Ex_OwnerOccupied) ";
cmd.CommandText += "VALUES ";
cmd.CommandText += "("+ r["ControlNumber"] +", "+ r["Jur_ID"] +", '"+ r["Jur_Status"] +"', '"+ r["Jur_Collected"] +"', '"+ r["1Jur_Yr"] +"', '"+ r["1Jur_Install"] +"', "+ r["1Jur_Amt"] +", "+ r["1Jur_Paid"] +", "+ r["1Jur_Due"] +", '"+ r["1Jur_DtDue"] +"', '"+ r["1Jur_FinalDue"] +"', '"+ r["1Jur_DtPaid"] +"', '"+ r["1Jur_Thru"] +"', ";
cmd.CommandText += "'"+ r["2Jur_Yr"] +"', '"+ r["2Jur_Install"] +"', "+ r["2Jur_Amt"] +", "+ r["2Jur_Paid"] +", "+ r["2Jur_Due"] +", '"+ r["2Jur_DtDue"] +"', '"+ r["2Jur_FinalDue"] +"', '"+ r["2Jur_DtPaid"] +"', '"+ r["2Jur_Thru"] +"', '"+ r["3Jur_Yr"] +"', '"+ r["3Jur_Install"] +"', "+ r["3Jur_Amt"] +", "+ r["3Jur_Paid"] +", "+ r["3Jur_Due"] +", '"+ r["3Jur_DtDue"] +"', '"+ r["3Jur_FinalDue"] +"', '"+ r["3Jur_DtPaid"] +"', '"+ r["3Jur_Thru"] +"', ";
cmd.CommandText += "'"+ r["4Jur_Yr"] +"', '"+ r["4Jur_Install"] +"', "+ r["4Jur_Amt"] +", "+ r["4Jur_Paid"] +", "+ r["4Jur_Due"] +", '"+ r["4Jur_DtDue"] +"', '"+ r["4Jur_FinalDue"] +"', '"+ r["4Jur_DtPaid"] +"', '"+ r["4Jur_Thru"] +"', '"+ r["Jur_PayNotes"] +"', '"+ r["Jur_OtherNotes"] +"', "+ r["MillageRate"] +", "+ r["AssessedValue"] +", "+ r["LandValue"] +", "+ r["ImprovedValue"] +", "+ r["TotalValue"] +", ";
cmd.CommandText += ""+ r["1Jur_DelAmount"] +", "+ r["2Jur_DelAmount"] +", "+ r["3Jur_DelAmount"] +", "+ r["4Jur_DelAmount"] +", '"+ r["Unincorporated"] +"', '"+ r["Ex_Homestead"] +"', '"+ r["Ex_Disabled"] +"', '"+ r["Ex_Veteran"] +"', '"+ r["Ex_Mortgage"] +"', '"+ r["Ex_Star"] +"', '"+ r["Ex_Elderly"] +"', '"+ r["Ex_Other"] +"', '"+ r["1Jur_Del"] +"', '"+ r["2Jur_Del"] +"', '"+ r["3Jur_Del"] +"', '"+ r["4Jur_Del"] +"', ";
cmd.CommandText += "'"+ r["DelVerifiedBy"] +"', "+ r["MilNextDue"] +", '"+ r["DelOverideNotes"] +"', '"+ r["SpokeTo"] +"', '"+ r["LumpSum"] +"', '"+ r["SchoolTax"] +"', '"+ r["PriorYearDel"] +"', '"+ r["1Jur_Partial"] +"', '"+ r["2Jur_Partial"] +"', '"+ r["3Jur_Partial"] +"', '"+ r["4Jur_Partial"] +"', '"+ r["1Jur_Timely"] +"', '"+ r["2Jur_Timely"] +"', '"+ r["3Jur_Timely"] +"', '"+ r["4Jur_Timely"] +"', ";
cmd.CommandText += "'"+ r["1Jur_FrDue"] +"', '"+ r["2Jur_FrDue"] +"', '"+ r["3Jur_FrDue"] +"', '"+ r["4Jur_FrDue"] +"', "+ r["LowestDiscount"] +", '"+ r["PaidDiscount"] +"', '"+ r["NoDiscount"] +"', '"+ r["PrimaryAuth"] +"', '"+ r["OtherAuth"] +"', '"+ r["MultiParcel"] +"', '"+ r["LandImprov"] +"', '"+ r["PriorYearDelq"] +"', '"+ r["AnyRedeemed"] +"', '"+ r["SpecialAssess"] +"', '"+ r["AnyExemptions"] +"', ";
cmd.CommandText += ""+ r["NextYearAssessment"] +", '"+ r["LastYearPaid"] +"', '"+ r["TaxSale"] +"', '"+ r["TaxRateArea"] +"', '"+ r["Ex_OwnerOccupied"]+ "'); ";
cmd.ExecuteNonQuery();
}
cmd.CommandText = INSERT INTO `FNF Taxes`(ControlNumber, Jur_ID, Jur_Status, Jur_Collected, 1Jur_Yr, 1Jur_Install, 1Jur_Amt, 1Jur_Paid, 1Jur_Due, 1Jur_DtDue, 1Jur_FinalDue, 1Jur_DtPaid, 1Jur_Thru, 2Jur_Yr, 2Jur_Install, 2Jur_Amt, 2Jur_Paid, 2Jur_Due, 2Jur_DtDue, 2Jur_FinalDue, 2Jur_DtPaid, 2Jur_Thru, 3Jur_Yr, 3Jur_Install, 3Jur_Amt, 3Jur_Paid, 3Jur_Due, 3Jur_DtDue, 3Jur_FinalDue, 3Jur_DtPaid, 3Jur_Thru, 4Jur_Yr, 4Jur_Install, 4Jur_Amt, 4Jur_Paid, 4Jur_Due, 4Jur_DtDue, 4Jur_FinalDue, 4Jur_DtPaid, 4Jur_Thru, Jur_PayNotes, Jur_OtherNotes, MillageRate, AssessedValue, LandValue, ImprovedValue, TotalValue, 1Jur_DelAmount, 2Jur_DelAmount, 3Jur_DelAmount, 4Jur_DelAmount, Unincorporated, Ex_Homestead, Ex_Disabled, Ex_Veteran, Ex_Mortgage, Ex_Star, Ex_Elderly, Ex_Other, 1Jur_Del, 2Jur_Del, 3Jur_Del, 4Jur_Del, DelVerifiedBy, MilNextDue, DelOverideNotes, SpokeTo, LumpSum, SchoolTax, PriorYearDel, 1Jur_Partial, 2Jur_Partial, 3Jur_Partial, 4Jur_Partial, 1Jur_Timely, 2Jur_Timely, 3Jur_Timely, 4Jur_Timely, 1Jur_FrDue, 2Jur_FrDue, 3Jur_FrDue, 4Jur_FrDue, LowestDiscount, PaidDiscount, NoDiscount, PrimaryAuth, OtherAuth, MultiParcel, LandImprov, PriorYearDelq, AnyRedeemed, SpecialAssess, AnyExemptions, NextYearAssessment, LastYearPaid, TaxSale, TaxRateArea, Ex_OwnerOccupied) VALUES (1291922, 1168, '', '', '2013', '1', 452.55, 452.55, , '9/30/2012 12:00:00 AM', '10/1/2012 12:00:00 AM', '9/30/2012 12:00:00 AM', '', '2013', '2', 452.55, 452.55, , '12/31/2012 12:00:00 AM', '1/1/2013 12:00:00 AM', '12/31/2012 12:00:00 AM', '', '2013', '3', 452.55, 452.55, , '3/31/2013 12:00:00 AM', '4/1/2013 12:00:00 AM', '3/31/2013 12:00:00 AM', '', '2013', '4', 452.55, 452.55, , '6/5/2013 12:00:00 AM', '6/6/2013 12:00:00 AM', '6/5/2013 12:00:00 AM', '', '', 'There are no special assessments for this property.', 1.05, 172400, 30000, 142400, 172400, , , , , 'False', 'False', 'False', 'False', 'False', 'False', 'False', '', 'False', 'False', 'False', 'False', '', 9/30/2013 12:00:00 AM, '', '', 'False', 'False', 'False', 'False', 'False', 'False', 'False', 'False', 'False', 'False', 'False', '9/1/2012 12:00:00 AM', '9/1/2012 12:00:00 AM', '9/1/2012 12:00:00 AM', '9/1/2012 12:00:00 AM', , 'False', 'False', 'False', 'Yes', 'No', 'Land and Improvements', 'No', 'No', 'No', 'No', , '', '', '', 'False');
答案 0 :(得分:2)
插入中有几个空的逗号集。在插入时间之前, ,
。
您可以尝试,'',
或,NULL,
答案 1 :(得分:0)
所以我继续前进并采用SQL参数方式(正确方式)并解决了我的问题。
'工作更聪明,而不是更努力'
foreach (DataRow r in dt.Rows)
{
cmd = connection.CreateCommand();
cmd.CommandText = "INSERT INTO `" + TableName + "`";
cmd.CommandText += "(ControlNumber, Jur_ID, Jur_Status, Jur_Collected, 1Jur_Yr, 1Jur_Install, 1Jur_Amt, 1Jur_Paid, 1Jur_Due, 1Jur_DtDue, 1Jur_FinalDue, 1Jur_DtPaid, 1Jur_Thru, ";
cmd.CommandText += "2Jur_Yr, 2Jur_Install, 2Jur_Amt, 2Jur_Paid, 2Jur_Due, 2Jur_DtDue, 2Jur_FinalDue, 2Jur_DtPaid, 2Jur_Thru, 3Jur_Yr, 3Jur_Install, 3Jur_Amt, 3Jur_Paid, 3Jur_Due, 3Jur_DtDue, 3Jur_FinalDue, 3Jur_DtPaid, 3Jur_Thru, ";
cmd.CommandText += "4Jur_Yr, 4Jur_Install, 4Jur_Amt, 4Jur_Paid, 4Jur_Due, 4Jur_DtDue, 4Jur_FinalDue, 4Jur_DtPaid, 4Jur_Thru, Jur_PayNotes, Jur_OtherNotes, MillageRate, AssessedValue, LandValue, ImprovedValue, TotalValue, ";
cmd.CommandText += "1Jur_DelAmount, 2Jur_DelAmount, 3Jur_DelAmount, 4Jur_DelAmount, Unincorporated, Ex_Homestead, Ex_Disabled, Ex_Veteran, Ex_Mortgage, Ex_Star, Ex_Elderly, Ex_Other, 1Jur_Del, 2Jur_Del, 3Jur_Del, 4Jur_Del, ";
cmd.CommandText += "DelVerifiedBy, MilNextDue, DelOverideNotes, SpokeTo, LumpSum, SchoolTax, PriorYearDel, 1Jur_Partial, 2Jur_Partial, 3Jur_Partial, 4Jur_Partial, 1Jur_Timely, 2Jur_Timely, 3Jur_Timely, 4Jur_Timely, ";
cmd.CommandText += "1Jur_FrDue, 2Jur_FrDue, 3Jur_FrDue, 4Jur_FrDue, LowestDiscount, PaidDiscount, NoDiscount, PrimaryAuth, OtherAuth, MultiParcel, LandImprov, PriorYearDelq, AnyRedeemed, SpecialAssess, AnyExemptions, ";
cmd.CommandText += "NextYearAssessment, LastYearPaid, TaxSale, TaxRateArea, Ex_OwnerOccupied) ";
cmd.CommandText += "VALUES ";
cmd.CommandText += "(@ControlNumber, @Jur_ID, @Jur_Status, @Jur_Collected, @1Jur_Yr, @1Jur_Install, @1Jur_Amt, @1Jur_Paid, @1Jur_Due, @1Jur_DtDue, @1Jur_FinalDue, @1Jur_DtPaid, @1Jur_Thru, ";
cmd.CommandText += "@2Jur_Yr, @2Jur_Install, @2Jur_Amt, @2Jur_Paid, @2Jur_Due, @2Jur_DtDue, @2Jur_FinalDue, @2Jur_DtPaid, @2Jur_Thru, @3Jur_Yr, @3Jur_Install, @3Jur_Amt, @3Jur_Paid, @3Jur_Due, @3Jur_DtDue, @3Jur_FinalDue, @3Jur_DtPaid, @3Jur_Thru, ";
cmd.CommandText += "@4Jur_Yr, @4Jur_Install, @4Jur_Amt, @4Jur_Paid, @4Jur_Due, @4Jur_DtDue, @4Jur_FinalDue, @4Jur_DtPaid, @4Jur_Thru, @Jur_PayNotes, @Jur_OtherNotes, @MillageRate, @AssessedValue, @LandValue, @ImprovedValue, @TotalValue, ";
cmd.CommandText += "@1Jur_DelAmount, @2Jur_DelAmount, @3Jur_DelAmount, @4Jur_DelAmount, @Unincorporated, @Ex_Homestead, @Ex_Disabled, @Ex_Veteran, @Ex_Mortgage, @Ex_Star, @Ex_Elderly, @Ex_Other, @1Jur_Del, @2Jur_Del, @3Jur_Del, @4Jur_Del, ";
cmd.CommandText += "@DelVerifiedBy, @MilNextDue, @DelOverideNotes, @SpokeTo, @LumpSum, @SchoolTax, @PriorYearDel, @1Jur_Partial, @2Jur_Partial, @3Jur_Partial, @4Jur_Partial, @1Jur_Timely, @2Jur_Timely, @3Jur_Timely, @4Jur_Timely, ";
cmd.CommandText += "@1Jur_FrDue, @2Jur_FrDue, @3Jur_FrDue, @4Jur_FrDue, @LowestDiscount, @PaidDiscount, @NoDiscount, @PrimaryAuth, @OtherAuth, @MultiParcel, @LandImprov, @PriorYearDelq, @AnyRedeemed, @SpecialAssess, @AnyExemptions, ";
cmd.CommandText += "@NextYearAssessment, @LastYearPaid, @TaxSale, @TaxRateArea, @Ex_OwnerOccupied); ";
cmd.Parameters.Add("@ControlNumber", r["ControlNumber"]);
cmd.Parameters.Add("@Jur_Id", r["Jur_ID"]);
cmd.Parameters.Add("@Jur_Status", r["Jur_Status"]);
cmd.Parameters.Add("@Jur_Collected", r["Jur_Collected"]);
cmd.Parameters.Add("@1Jur_Yr", r["1Jur_Yr"]);
cmd.Parameters.Add("@1Jur_Install", r["1Jur_Install"]);
cmd.Parameters.Add("@1Jur_Amt", r["1Jur_Amt"]);
cmd.Parameters.Add("@1Jur_Paid", r["1Jur_Paid"]);
cmd.Parameters.Add("@1Jur_Due", r["1Jur_Due"]);
cmd.Parameters.Add("@1Jur_DtDue", r["1Jur_DtDue"]);
cmd.Parameters.Add("@1Jur_FinalDue", r["1Jur_FinalDue"]);
cmd.Parameters.Add("@1Jur_DtPaid", r["1Jur_DtPaid"]);
cmd.Parameters.Add("@1Jur_Thru", r["1Jur_Thru"]);
cmd.Parameters.Add("@2Jur_Yr", r["2Jur_Yr"]);
cmd.Parameters.Add("@2Jur_Install", r["2Jur_Install"]);
cmd.Parameters.Add("@2Jur_Amt", r["2Jur_Amt"]);
cmd.Parameters.Add("@2Jur_Paid", r["2Jur_Paid"]);
cmd.Parameters.Add("@2Jur_Due", r["2Jur_Due"]);
cmd.Parameters.Add("@2Jur_DtDue", r["2Jur_DtDue"]);
cmd.Parameters.Add("@2Jur_FinalDue", r["2Jur_FinalDue"]);
cmd.Parameters.Add("@2Jur_DtPaid", r["2Jur_DtPaid"]);
cmd.Parameters.Add("@2Jur_Thru", r["2Jur_Thru"]);
cmd.Parameters.Add("@3Jur_Yr", r["3Jur_Yr"]);
cmd.Parameters.Add("@3Jur_Install", r["3Jur_Install"]);
cmd.Parameters.Add("@3Jur_Amt", r["3Jur_Amt"]);
cmd.Parameters.Add("@3Jur_Paid", r["3Jur_Paid"]);
cmd.Parameters.Add("@3Jur_Due", r["3Jur_Due"]);
cmd.Parameters.Add("@3Jur_DtDue", r["3Jur_DtDue"]);
cmd.Parameters.Add("@3Jur_FinalDue", r["3Jur_FinalDue"]);
cmd.Parameters.Add("@3Jur_DtPaid", r["3Jur_DtPaid"]);
cmd.Parameters.Add("@3Jur_Thru", r["3Jur_Thru"]);
cmd.Parameters.Add("@4Jur_Yr", r["4Jur_Yr"]);
cmd.Parameters.Add("@4Jur_Install", r["4Jur_Install"]);
cmd.Parameters.Add("@4Jur_Amt", r["4Jur_Amt"]);
cmd.Parameters.Add("@4Jur_Paid", r["4Jur_Paid"]);
cmd.Parameters.Add("@4Jur_Due", r["4Jur_Due"]);
cmd.Parameters.Add("@4Jur_DtDue", r["4Jur_DtDue"]);
cmd.Parameters.Add("@4Jur_FinalDue", r["4Jur_FinalDue"]);
cmd.Parameters.Add("@4Jur_DtPaid", r["4Jur_DtPaid"]);
cmd.Parameters.Add("@4Jur_Thru", r["4Jur_Thru"]);
cmd.Parameters.Add("@Jur_PayNotes", r["Jur_PayNotes"]);
cmd.Parameters.Add("@Jur_OtherNotes", r["Jur_otherNotes"]);
cmd.Parameters.Add("@MillageRate", r["MillageRate"]);
cmd.Parameters.Add("@AssessedValue", r["AssessedValue"]);
cmd.Parameters.Add("@LandValue", r["LandValue"]);
cmd.Parameters.Add("@ImprovedValue", r["ImprovedValue"]);
cmd.Parameters.Add("@TotalValue", r["TotalValue"]);
cmd.Parameters.Add("@1Jur_DelAmount", r["1Jur_DelAmount"]);
cmd.Parameters.Add("@2Jur_DelAmount", r["2Jur_DelAmount"]);
cmd.Parameters.Add("@3Jur_DelAmount", r["3Jur_DelAmount"]);
cmd.Parameters.Add("@4Jur_DelAmount", r["4Jur_DelAmount"]);
cmd.Parameters.Add("@Unincorporated", r["Unincorporated"]);
cmd.Parameters.Add("@Ex_Homestead", r["Ex_Homestead"]);
cmd.Parameters.Add("@Ex_Disabled", r["Ex_Disabled"]);
cmd.Parameters.Add("@Ex_Veteran", r["Ex_Veteran"]);
cmd.Parameters.Add("@Ex_Mortgage", r["Ex_Mortgage"]);
cmd.Parameters.Add("@Ex_Star", r["Ex_Star"]);
cmd.Parameters.Add("@Ex_Elderly", r["Ex_Elderly"]);
cmd.Parameters.Add("@Ex_Other", r["Ex_Other"]);
cmd.Parameters.Add("@1Jur_Del", r["1Jur_Del"]);
cmd.Parameters.Add("@2Jur_Del", r["2Jur_Del"]);
cmd.Parameters.Add("@3Jur_Del", r["3Jur_Del"]);
cmd.Parameters.Add("@4Jur_Del", r["4Jur_Del"]);
cmd.Parameters.Add("@DelVerifiedBy", r["DelVerifiedBy"]);
cmd.Parameters.Add("@MilNextDue", r["MilNextDue"]);
cmd.Parameters.Add("@DelOverideNotes", r["DelOverideNotes"]);
cmd.Parameters.Add("@SpokeTo", r["SpokeTo"]);
cmd.Parameters.Add("@LumpSum", r["LumpSum"]);
cmd.Parameters.Add("@SchoolTax", r["SchoolTax"]);
cmd.Parameters.Add("@PriorYearDel", r["PriorYearDel"]);
cmd.Parameters.Add("@1Jur_Partial", r["1Jur_Partial"]);
cmd.Parameters.Add("@2Jur_Partial", r["2Jur_Partial"]);
cmd.Parameters.Add("@3Jur_Partial", r["3Jur_Partial"]);
cmd.Parameters.Add("@4Jur_Partial", r["4Jur_Partial"]);
cmd.Parameters.Add("@1Jur_Timely", r["1Jur_Timely"]);
cmd.Parameters.Add("@2Jur_Timely", r["2Jur_Timely"]);
cmd.Parameters.Add("@3Jur_Timely", r["3Jur_Timely"]);
cmd.Parameters.Add("@4Jur_Timely", r["4Jur_Timely"]);
cmd.Parameters.Add("@1Jur_FrDue", r["1Jur_FrDue"]);
cmd.Parameters.Add("@2Jur_FrDue", r["2Jur_FrDue"]);
cmd.Parameters.Add("@3Jur_FrDue", r["3Jur_FrDue"]);
cmd.Parameters.Add("@4Jur_FrDue", r["4Jur_FrDue"]);
cmd.Parameters.Add("@LowestDiscount", r["LowestDiscount"]);
cmd.Parameters.Add("@PaidDiscount", r["PaidDiscount"]);
cmd.Parameters.Add("@NoDiscount", r["NoDiscount"]);
cmd.Parameters.Add("@PrimaryAuth", r["PrimaryAuth"]);
cmd.Parameters.Add("@OtherAuth", r["OtherAuth"]);
cmd.Parameters.Add("@MultiParcel", r["MultiParcel"]);
cmd.Parameters.Add("@LandImprov", r["LandImprov"]);
cmd.Parameters.Add("@PriorYearDelq", r["PriorYearDelq"]);
cmd.Parameters.Add("@AnyRedeemed", r["AnyRedeemed"]);
cmd.Parameters.Add("@SpecialAssess", r["SpecialAssess"]);
cmd.Parameters.Add("@AnyExemptions", r["AnyExemptions"]);
cmd.Parameters.Add("@NextYearAssessment", r["NextYearAssessment"]);
cmd.Parameters.Add("@LastYearPaid", r["LastYearPaid"]);
cmd.Parameters.Add("@TaxSale", r["TaxSale"]);
cmd.Parameters.Add("@TaxRateArea", r["TaxRateArea"]);
cmd.Parameters.Add("@Ex_OwnerOccupied", r["Ex_OwnerOccupied"]);
cmd.ExecuteNonQuery();
}
答案 2 :(得分:0)
我会进一步采用你自己的解决方案......你正在为每条记录重建命令,字符串和参数。我会按以下方式调整......
(假设您至少有一行,并且您已对此进行了测试)
DataRow r = dt.Rows[0];
cmd = ...
cmd.CommandText = ... (as you already have parameterized).
定义参数ONCE(就像你一样)。
cmd.Parameters.Add("@ControlNumber", r["ControlNumber"]);
cmd.Parameters.Add("@Jur_Id", r["Jur_ID"]);
cmd.Parameters.Add("@Jur_Status", r["Jur_Status"]);
...
现在,您已经完成了所有构建和参数的命令...现在,您可以遍历每一行并只更新每行的参数值(因此不必继续重建参数和所有创造每次的开销)......
foreach (DataRow r2 in dt.Rows)
{
// just keep the parameters in the same sequence as you have when creating
// you just update the value that will be applied when executed.
cmd.Parameters[0].Value = r2["ControlNumber"]);
cmd.Parameters[1].Value = r2["Jur_ID"]);
cmd.Parameters[2].Value = r2["Jur_Status"]);
...
cmd.ExecuteNonQuery();
}