我有一个存储的Proc:
USE [RMV1]
GO
ALTER PROCEDURE [dbo].[INS_Respond_Local]
@phone varchar(15),
@wphone varchar(15),
@wphone_ext varchar(5),
@fax varchar(15),
@cell varchar(15),
@email varchar(30),
@areacode varchar(3),
@areacode_w varchar(3),
@lname varchar(30),
@fname varchar(30),
@city varchar(20),
@state varchar(2),
@zip varchar(10),
@county varchar(20),
@employer varchar(50),
@occupation varchar(50),
@jobcode varchar(3),
@employ_status varchar(2),
@DOB datetime,
@gender varchar(1),
@maritalstatus varchar(1),
@income varchar(1),
@education varchar(2),
@race varchar(2),
@Party varchar(2),
@typehome varchar(2),
@spousejobcode varchar(3),
@spousehours varchar(2),
@child1 varchar(1),
@childbd1 datetime,
@child2 varchar(1),
@childbd2 datetime,
@child3 varchar(1),
@childbd3 datetime,
@child4 varchar(1),
@childbd4 datetime,
@child5 varchar(1),
@childbd5 datetime,
@child6 varchar(1),
@childbd6 datetime,
@resp_type varchar(5),
@C1_OnLine varchar(100),
@C2_Pets varchar(100),
@C3_Onlinepr varchar(100),
@C4_Gamesyste varchar(100),
@C5_Alcohol varchar(100),
@C6_Technology varchar(100),
@C7_PersonalI varchar(100),
@C8_Health varchar(100),
@C9_MDSpecial varchar(100),
@C10_PDASmart varchar(100),
@C11_TypeofCo varchar(100),
@C12_CreditCar varchar(100),
@C13_Cigarettes varchar(100),
@C14_Position varchar(100),
@C15_MDStatus varchar(100),
@C16_MDPractic varchar(100),
@C17_MDTypePr varchar(100),
@C18_NumLocal varchar(100),
@C19_NumEmploy varchar(100),
@C20_BusinessT varchar(100),
@C21_PleasureT varchar(100),
@C22_LocalPhon varchar(100),
@C23_LongDista varchar(100),
@C24_HealthIns varchar(100),
@C25_Industry varchar(100),
@C26_Employers varchar(100),
@C27_NumberEmp varchar(100),
@C28_NumberCom varchar(100),
@C29_CellPhone varchar(100),
@C30_TypeofTV varchar(100),
@C31_MusicPref varchar(100),
@C32_Cigarette varchar(100),
@C33_MD varchar(100),
@C34_TypeofCo varchar(100),
@C35_MDSubSpe varchar(100),
@C36_USMedSch varchar(100),
@C37_SexualOri varchar(100),
@C38_PersonalI varchar(100),
@C39_Source varchar(100),
@C40_Recreation varchar(100),
@C41_SocialProf varchar(100),
@C42_NumIntl varchar(100),
@C43_NumIntl varchar(100),
@C44_NumDomest varchar(100),
@C45_NumDomest varchar(100),
@C46_Languages varchar(100),
@C47_HomePhone varchar(100),
@C48_OtherToba varchar(100),
@C49_Lifestyle varchar(100),
@C50_Attitudes varchar(100),
@c_brand varchar(50),
@c_flavor varchar(50),
@c_length varchar(50),
@c_type varchar(50),
@c_past_purch varchar(50),
@c_oth_brnd varchar(50),
@car_make_1 varchar(5),
@car_model_1 varchar(5),
@car_year_1 varchar(4),
@car_options_1 varchar(255),
@car_make_2 varchar(5),
@car_model_2 varchar(5),
@car_year_2 varchar(4),
@car_options_2 varchar(255)
AS
INSERT INTO [dbo].[Respondent]
([phone],[wphone],[wphone_ext],[fax],[cellphone],[email],[area_code], [area_code_w],[lname],[fname],[address],[city],[state]
,[zip],[county],[address_w],[city_w],[state_w],[zip_w],[county_w], [employer],[Occ_title],[jobcode],[hours],[datebirth],[gender]
,[maritalstatus],[income],[education],[race],[Party],[typehome], [spousejobcode],[spousehours],[childgen1],[childbd1],[childgen2]
,[childbd2],[childgen3],[childbd3],[childgen4],[childbd4],[childgen5], [childbd5],[childgen6],[childbd6],[resp_type],[dateenter]
,[dateupdated],[referred_by_resp],[Pro_resp],[Caution_Flag], [last_selection],[last_participation],[number_parts],[calling_note]
,[notes],[CB1],[CB2],[CB3],[CB4],[CB5],[CB6],[CB7],[CB8],[CB9],[CC1],[CC2], [CC3],[CC4],[CC5],[CC6],[CC7],[CC8],[CC9],[CC10],[CC11]
,[CC12],[CC13],[CC14],[CC15],[CC16],[CC17],[CC18],[CC19],[CC20],[CC21], [CC22],[CC23],[CC24],[CC25],[CC26],[CC27],[CC28],[CC29]
,[CC30],[CC31],[CC32],[CC33],[CC34],[CC35],[CC36],[CC37],[CC38],[CC39], [CC40],[CC41],[CC42],[CC43],[CC44],[CC45],[CC46],[CC47]
,[CC48],[CC49],[CC50],[c_brand],[c_flavor],[c_length],[c_type], [c_past_purchases],[c_other_brands],[car_make_1],[car_model_1]
,[car_year_1],[car_options_1],[car_make_2],[car_model_2],[car_year_2], [car_options_2])
VALUES
( @phone
,@wphone
,@wphone_ext
,@fax
,@cell
,@email
,@areacode
,@areacode_w
,@lname
,@fname
,''
,@city
,@state
,@zip
,@county
,null
,null
,null
,null
,null
,@employer
,@occupation
,@jobcode
,@employ_status
,@DOB
,@gender
,@maritalstatus
,@income
,@education
,@race
,@Party
,@typehome
,@spousejobcode
,@spousehours
,@child1
,@childbd1
,@child2
,@childbd2
,@child3
,@childbd3
,@child4
,@childbd4
,@child5
,@childbd5
,@child6
,@childbd6
,@resp_type
,GETDATE()
,null
,0
,''
,null
,null
,null
,0
,null
,null
,0
,0
,0
,0
,0
,0
,0
,0
,0
,@C1_OnLine
,@C2_Pets
,@C3_Onlinepr
,@C4_Gamesyste
,@C5_Alcohol
,@C6_Technology
,@C7_PersonalI
,@C8_Health
,@C9_MDSpecial
,@C10_PDASmart
,@C11_TypeofCo
,@C12_CreditCar
,@C13_Cigarettes
,@C14_Position
,@C15_MDStatus
,@C16_MDPractic
,@C17_MDTypePr
,@C18_NumLocal
,@C19_NumEmploy
,@C20_BusinessT
,@C21_PleasureT
,@C22_LocalPhon
,@C23_LongDista
,@C24_HealthIns
,@C25_Industry
,@C26_Employers
,@C27_NumberEmp
,@C28_NumberCom
,@C29_CellPhone
,@C30_TypeofTV
,@C31_MusicPref
,@C32_Cigarette
,@C33_MD
,@C34_TypeofCo
,@C35_MDSubSpe
,@C36_USMedSch
,@C37_SexualOri
,@C38_PersonalI
,@C39_Source
,@C40_Recreation
,@C41_SocialProf
,@C42_NumIntl
,@C43_NumIntl
,@C44_NumDomest
,@C45_NumDomest
,@C46_Languages
,@C47_HomePhone
,@C48_OtherToba
,@C49_Lifestyle
,@C50_Attitudes
,@c_brand
,@c_flavor
,@c_length
,@c_type
,@c_past_purch
,@c_oth_brnd
,@car_make_1
,@car_model_1
,@car_year_1
,@car_options_1
,@car_make_2
,@car_model_2
,@car_year_2
,@car_options_2)
我正在用C#中的ADO类调用它...
using (var con = new SqlConnection())
{
con.ConnectionString = @"Data Source=.\DEV2008;Initial Catalog=RMV1;Persist Security Info=True;User ID=sa;Password=********";
try
{
con.Open();
var cmd = new SqlCommand("INS_Respond_Local", con) {CommandType = CommandType.StoredProcedure};
#region DeclareSQL
cmd.Parameters.Add("@phone", SqlDbType.NVarChar, 15);
cmd.Parameters.Add("@wphone", SqlDbType.NVarChar, 15);
cmd.Parameters.Add("@wphone_ext", SqlDbType.NVarChar, 5);
cmd.Parameters.Add("@fax", SqlDbType.NVarChar, 15);
cmd.Parameters.Add("@cell", SqlDbType.NVarChar, 15);
cmd.Parameters.Add("@email", SqlDbType.NVarChar, 30);
cmd.Parameters.Add("@areacode", SqlDbType.NVarChar, 3);
cmd.Parameters.Add("@areacode_w", SqlDbType.NVarChar, 3);
cmd.Parameters.Add("@lname", SqlDbType.NVarChar, 30);
cmd.Parameters.Add("@fname", SqlDbType.NVarChar, 30);
cmd.Parameters.Add("@city", SqlDbType.NVarChar, 20);
cmd.Parameters.Add("@state", SqlDbType.NVarChar, 2);
cmd.Parameters.Add("@zip", SqlDbType.NVarChar, 10);
cmd.Parameters.Add("@county", SqlDbType.NVarChar, 20);
cmd.Parameters.Add("@employer", SqlDbType.NVarChar, 50);
cmd.Parameters.Add("@occupation", SqlDbType.NVarChar, 20);
cmd.Parameters.Add("@jobcode", SqlDbType.NVarChar, 3);
cmd.Parameters.Add("@employ_status", SqlDbType.NVarChar, 2);
cmd.Parameters.Add("@DOB", SqlDbType.DateTime);
cmd.Parameters.Add("@gender", SqlDbType.NVarChar, 1);
cmd.Parameters.Add("@maritalstatus", SqlDbType.NVarChar, 1);
cmd.Parameters.Add("@income", SqlDbType.NVarChar, 1);
cmd.Parameters.Add("@education", SqlDbType.NVarChar, 2);
cmd.Parameters.Add("@race", SqlDbType.NVarChar, 2);
cmd.Parameters.Add("@Party", SqlDbType.NVarChar, 2);
cmd.Parameters.Add("@typehome", SqlDbType.NVarChar, 2);
cmd.Parameters.Add("@spousejobcode", SqlDbType.NVarChar, 3);
cmd.Parameters.Add("@spousehours", SqlDbType.NVarChar, 2);
cmd.Parameters.Add("@child1", SqlDbType.NVarChar, 1);
cmd.Parameters.Add("@childbd1", SqlDbType.DateTime);
cmd.Parameters.Add("@child2", SqlDbType.NVarChar, 1);
cmd.Parameters.Add("@childbd2", SqlDbType.DateTime);
cmd.Parameters.Add("@child3", SqlDbType.NVarChar, 1);
cmd.Parameters.Add("@childbd3", SqlDbType.DateTime);
cmd.Parameters.Add("@child4", SqlDbType.NVarChar, 1);
cmd.Parameters.Add("@childbd4", SqlDbType.DateTime);
cmd.Parameters.Add("@child5", SqlDbType.NVarChar, 1);
cmd.Parameters.Add("@childbd5", SqlDbType.DateTime);
cmd.Parameters.Add("@child6", SqlDbType.NVarChar, 1);
cmd.Parameters.Add("@childbd6", SqlDbType.DateTime);
cmd.Parameters.Add("@resp_type", SqlDbType.NVarChar, 5);
cmd.Parameters.Add("@C1_OnLine", SqlDbType.NVarChar, 100);
cmd.Parameters.Add("@C2_Pets", SqlDbType.NVarChar, 100);
cmd.Parameters.Add("@C3_Onlinepr", SqlDbType.NVarChar, 100);
cmd.Parameters.Add("@C4_Gamesyste", SqlDbType.NVarChar, 100);
cmd.Parameters.Add("@C5_Alcohol", SqlDbType.NVarChar, 100);
cmd.Parameters.Add("@C6_Technology", SqlDbType.NVarChar, 100);
cmd.Parameters.Add("@C7_PersonalI", SqlDbType.NVarChar, 100);
cmd.Parameters.Add("@C8_Health", SqlDbType.NVarChar, 100);
cmd.Parameters.Add("@C9_MDSpecial", SqlDbType.NVarChar, 100);
cmd.Parameters.Add("@C10_PDASmart", SqlDbType.NVarChar, 100);
cmd.Parameters.Add("@C11_TypeofCo", SqlDbType.NVarChar, 100);
cmd.Parameters.Add("@C12_CreditCar", SqlDbType.NVarChar, 100);
cmd.Parameters.Add("@C13_Cigarettes", SqlDbType.NVarChar, 100);
cmd.Parameters.Add("@C14_Position", SqlDbType.NVarChar, 100);
cmd.Parameters.Add("@C15_MDStatus", SqlDbType.NVarChar, 100);
cmd.Parameters.Add("@C16_MDPractic", SqlDbType.NVarChar, 100);
cmd.Parameters.Add("@C17_MDTypePr", SqlDbType.NVarChar, 100);
cmd.Parameters.Add("@C18_NumLocal", SqlDbType.NVarChar, 100);
cmd.Parameters.Add("@C19_NumEmploy", SqlDbType.NVarChar, 100);
cmd.Parameters.Add("@C20_BusinessT", SqlDbType.NVarChar, 100);
cmd.Parameters.Add("@C21_PleasureT", SqlDbType.NVarChar, 100);
cmd.Parameters.Add("@C22_LocalPhon", SqlDbType.NVarChar, 100);
cmd.Parameters.Add("@C23_LongDista", SqlDbType.NVarChar, 100);
cmd.Parameters.Add("@C24_HealthIns", SqlDbType.NVarChar, 100);
cmd.Parameters.Add("@C25_Industry", SqlDbType.NVarChar, 100);
cmd.Parameters.Add("@C26_Employers", SqlDbType.NVarChar, 100);
cmd.Parameters.Add("@C27_NumberEmp", SqlDbType.NVarChar, 100);
cmd.Parameters.Add("@C28_NumberCom", SqlDbType.NVarChar, 100);
cmd.Parameters.Add("@C29_CellPhone", SqlDbType.NVarChar, 100);
cmd.Parameters.Add("@C30_TypeofTV", SqlDbType.NVarChar, 100);
cmd.Parameters.Add("@C31_MusicPref", SqlDbType.NVarChar, 100);
cmd.Parameters.Add("@C32_Cigarette", SqlDbType.NVarChar, 100);
cmd.Parameters.Add("@C33_MD", SqlDbType.NVarChar, 100);
cmd.Parameters.Add("@C34_TypeofCo", SqlDbType.NVarChar, 100);
cmd.Parameters.Add("@C35_MDSubSpe", SqlDbType.NVarChar, 100);
cmd.Parameters.Add("@C36_USMedSch", SqlDbType.NVarChar, 100);
cmd.Parameters.Add("@C37_SexualOri", SqlDbType.NVarChar, 100);
cmd.Parameters.Add("@C38_PersonalI", SqlDbType.NVarChar, 100);
cmd.Parameters.Add("@C39_Source", SqlDbType.NVarChar, 100);
cmd.Parameters.Add("@C40_Recreation", SqlDbType.NVarChar, 100);
cmd.Parameters.Add("@C41_SocialProf", SqlDbType.NVarChar, 100);
cmd.Parameters.Add("@C42_NumIntl", SqlDbType.NVarChar, 100);
cmd.Parameters.Add("@C43_NumIntl", SqlDbType.NVarChar, 100);
cmd.Parameters.Add("@C44_NumDomest", SqlDbType.NVarChar, 100);
cmd.Parameters.Add("@C45_NumDomest", SqlDbType.NVarChar, 100);
cmd.Parameters.Add("@C46_Languages", SqlDbType.NVarChar, 100);
cmd.Parameters.Add("@C47_HomePhone", SqlDbType.NVarChar, 100);
cmd.Parameters.Add("@C48_OtherToba", SqlDbType.NVarChar, 100);
cmd.Parameters.Add("@C49_Lifestyle", SqlDbType.NVarChar, 100);
cmd.Parameters.Add("@C50_Attitudes", SqlDbType.NVarChar, 100);
cmd.Parameters.Add("@c_brand", SqlDbType.NVarChar, 50);
cmd.Parameters.Add("@c_flavor", SqlDbType.NVarChar, 50);
cmd.Parameters.Add("@c_length", SqlDbType.NVarChar, 50);
cmd.Parameters.Add("@c_type", SqlDbType.NVarChar, 50);
cmd.Parameters.Add("@c_past_purch", SqlDbType.NVarChar, 50);
cmd.Parameters.Add("@c_oth_brnd", SqlDbType.NVarChar, 50);
cmd.Parameters.Add("@car_make_1", SqlDbType.NVarChar, 5);
cmd.Parameters.Add("@car_model_1", SqlDbType.NVarChar, 5);
cmd.Parameters.Add("@car_year_1", SqlDbType.NVarChar, 4);
cmd.Parameters.Add("@car_options_1", SqlDbType.NVarChar, 255);
cmd.Parameters.Add("@car_make_2", SqlDbType.NVarChar, 5);
cmd.Parameters.Add("@car_model_2", SqlDbType.NVarChar, 5);
cmd.Parameters.Add("@car_year_2", SqlDbType.NVarChar, 4);
cmd.Parameters.Add("@car_options_2", SqlDbType.NVarChar, 255);
#endregion
#region AssignValues
cmd.Parameters["@phone"].Value = a.phone;
cmd.Parameters["@wphone"].Value = a.wphone;
cmd.Parameters["@wphone_ext"].Value = a.wphone_ext;
cmd.Parameters["@fax"].Value = a.fax;
cmd.Parameters["@cell"].Value = a.cellphone;
cmd.Parameters["@email"].Value = a.email;
cmd.Parameters["@areacode"].Value = a.area_code;
cmd.Parameters["@areacode_w"].Value = a.area_code_w;
cmd.Parameters["@lname"].Value = a.lname;
cmd.Parameters["@fname"].Value = a.fname;
cmd.Parameters["@city"].Value = a.city;
cmd.Parameters["@state"].Value = a.state;
cmd.Parameters["@zip"].Value = a.zip;
cmd.Parameters["@county"].Value = a.county;
cmd.Parameters["@employer"].Value = a.employer;
cmd.Parameters["@occupation"].Value = a.Occ_title;
cmd.Parameters["@jobcode"].Value = a.jobcode;
cmd.Parameters["@employ_status"].Value = a.hours;
cmd.Parameters["@DOB"].Value = a.datebirth;
cmd.Parameters["@gender"].Value = a.gender;
cmd.Parameters["@maritalstatus"].Value = a.maritalstatus;
cmd.Parameters["@income"].Value = a.income;
cmd.Parameters["@education"].Value = a.education;
cmd.Parameters["@race"].Value = a.race;
cmd.Parameters["@Party"].Value = a.Party;
cmd.Parameters["@typehome"].Value = a.typehome;
cmd.Parameters["@spousejobcode"].Value = a.spousejobcode;
cmd.Parameters["@spousehours"].Value = a.spousehours;
cmd.Parameters["@child1"].Value = a.childgen1;
cmd.Parameters["@childbd1"].Value = a.childbd1;
cmd.Parameters["@child2"].Value = a.childgen2;
cmd.Parameters["@childbd2"].Value = a.childbd2;
cmd.Parameters["@child3"].Value = a.childgen3;
cmd.Parameters["@childbd3"].Value = a.childbd3;
cmd.Parameters["@child4"].Value = a.childgen4;
cmd.Parameters["@childbd4"].Value = a.childbd4;
cmd.Parameters["@child5"].Value = a.childgen5;
cmd.Parameters["@childbd5"].Value = a.childbd5;
cmd.Parameters["@child6"].Value = a.childgen6;
cmd.Parameters["@childbd6"].Value = a.childbd6;
cmd.Parameters["@resp_type"].Value = a.resp_type;
cmd.Parameters["@C1_OnLine"].Value = a.CC1;
cmd.Parameters["@C2_Pets"].Value = a.CC2;
cmd.Parameters["@C3_Onlinepr"].Value = a.CC3;
cmd.Parameters["@C4_Gamesyste"].Value = a.CC4;
cmd.Parameters["@C5_Alcohol"].Value = a.CC5;
cmd.Parameters["@C6_Technology"].Value = a.CC6;
cmd.Parameters["@C7_PersonalI"].Value = a.CC7;
cmd.Parameters["@C8_Health"].Value = a.CC8;
cmd.Parameters["@C9_MDSpecial"].Value = a.CC9;
cmd.Parameters["@C10_PDASmart"].Value = a.CC10;
cmd.Parameters["@C11_TypeofCo"].Value = a.CC11;
cmd.Parameters["@C12_CreditCar"].Value = a.CC12;
cmd.Parameters["@C13_Cigarettes"].Value = a.CC13;
cmd.Parameters["@C14_Position"].Value = a.CC14;
cmd.Parameters["@C15_MDStatus"].Value = a.CC15;
cmd.Parameters["@C16_MDPractic"].Value = a.CC16;
cmd.Parameters["@C17_MDTypePr"].Value = a.CC17;
cmd.Parameters["@C18_NumLocal"].Value = a.CC18;
cmd.Parameters["@C19_NumEmploy"].Value = a.CC19;
cmd.Parameters["@C20_BusinessT"].Value = a.CC20;
cmd.Parameters["@C21_PleasureT"].Value = a.CC21;
cmd.Parameters["@C22_LocalPhon"].Value = a.CC22;
cmd.Parameters["@C23_LongDista"].Value = a.CC23;
cmd.Parameters["@C24_HealthIns"].Value = a.CC24;
cmd.Parameters["@C25_Industry"].Value = a.CC25;
cmd.Parameters["@C26_Employers"].Value = a.CC26;
cmd.Parameters["@C27_NumberEmp"].Value = a.CC27;
cmd.Parameters["@C28_NumberCom"].Value = a.CC28;
cmd.Parameters["@C29_CellPhone"].Value = a.CC29;
cmd.Parameters["@C30_TypeofTV"].Value = a.CC30;
cmd.Parameters["@C31_MusicPref"].Value = a.CC31;
cmd.Parameters["@C32_Cigarette"].Value = a.CC32;
cmd.Parameters["@C33_MD"].Value = a.CC33;
cmd.Parameters["@C34_TypeofCo"].Value = a.CC34;
cmd.Parameters["@C35_MDSubSpe"].Value = a.CC35;
cmd.Parameters["@C36_USMedSch"].Value = a.CC36;
cmd.Parameters["@C37_SexualOri"].Value = a.CC37;
cmd.Parameters["@C38_PersonalI"].Value = a.CC38;
cmd.Parameters["@C39_Source"].Value = a.CC39;
cmd.Parameters["@C40_Recreation"].Value = a.CC40;
cmd.Parameters["@C41_SocialProf"].Value = a.CC41;
cmd.Parameters["@C42_NumIntl"].Value = a.CC42;
cmd.Parameters["@C43_NumIntl"].Value = a.CC43;
cmd.Parameters["@C44_NumDomest"].Value = a.CC44;
cmd.Parameters["@C45_NumDomest"].Value = a.CC45;
cmd.Parameters["@C46_Languages"].Value = a.CC46;
cmd.Parameters["@C47_HomePhone"].Value = a.CC47;
cmd.Parameters["@C48_OtherToba"].Value = a.CC48;
cmd.Parameters["@C49_Lifestyle"].Value = a.CC49;
cmd.Parameters["@C50_Attitudes"].Value = a.CC50;
cmd.Parameters["@c_brand"].Value = "";
cmd.Parameters["@c_flavor"].Value = "";
cmd.Parameters["@c_length"].Value = "";
cmd.Parameters["@c_type"].Value = "";
cmd.Parameters["@c_past_purch"].Value = "";
cmd.Parameters["@c_oth_brnd"].Value = "";
cmd.Parameters["@car_make_1"].Value = a.car_make_1;
cmd.Parameters["@car_model_1"].Value = a.car_model_1;
cmd.Parameters["@car_year_1"].Value = a.car_year_1;
cmd.Parameters["@car_options_1"].Value = "";
cmd.Parameters["@car_make_2"].Value = a.car_make_2;
cmd.Parameters["@car_model_2"].Value = a.car_model_2;
cmd.Parameters["@car_year_2"].Value = a.car_year_2;
cmd.Parameters["@car_options_2"].Value = "";
#endregion
cmd.ExecuteNonQuery();
}
finally
{
con.Close();
}
}
我用一把细齿梳子经历了这个问题,当我打电话给它时,我得到一个缺少参数的错误
过程或函数'INS_Respond_Local'需要参数'@fax',这是未提供的。
@fax就在那里,如果我摆脱它是@count ...我读here ADO存储过程参数有错误但是这是在CLR或ActiveX?无论如何这真的是一个错误,或者我只是愚蠢......?如果它是一个bug,我该如何解决它。
答案 0 :(得分:2)
对于可以为空的所有内容,请执行以下操作:
cmd.Parameters["@theParam"].Value = (object)a.TheParam ?? DBNull.Value;
如果您喜欢,可以将此逻辑放在扩展方法中。
答案 1 :(得分:1)
有可能a.fax的值是null
而不是空字符串。
您应该提供DBNull.Value而不是null。
答案 2 :(得分:0)
我在Classic ASP(VBScript)中遇到了这个错误,当我为参数赋值时,当我们尝试从Request.Form中分配一个未提交的值时,会出现此错误,但在ASP Classic中,当它没有被提交时,它应该是字符串,但是ADODB会做其他事情(并且它不是空的,可能在c#中)。
所以我们的解决方法是创建一个如下所示的函数:
Function ReplaceEmptyWith(value, replace)
If value = "" Then
ReplaceEmptyWith = replace
Else
ReplaceEmptyWith = value
End If
End Function
因此,在参数赋值时,我们调用ReplaceEmptyWith(a.fax,“”)或C#中的等价物