我收到错误"带有ParameterName的#SqlParameter' @ BPBILL_PLAN_DESCRIPTION'不包含在此SqlParameterCollection中。"我无法弄清楚为什么它对其他所有领域都没问题,但这个错误。
string[] lines7 = System.IO.File.ReadAllLines(@"C:\\BillingExport\BILLING_TABLE_FILE17.txt");
//creating a list for segmented storage of the data in the text file
List<BILL_PLAN_DESCRIPTION> table17Input = new List<BILL_PLAN_DESCRIPTION>();
//iterates through every line in the text file (one line at a time) , trims the data in regions appropriate to their fields , and assigns the trimmed data to list items.
for (int i = 0; i < lines7.Length; i++)
{
BILL_PLAN_DESCRIPTION table17 = new BILL_PLAN_DESCRIPTION();
//creates new list instance (table5)
//trims the data in regions appropriate to their fields , converts the data into its proper datatype (reflecting the sql field datatype), and assigns the trimmed data to list items.
table17.BPTABLE_NUMBER = lines7[i].Substring(0, 2).Trim();
table17.BPCOMPANY = lines7[i].Substring(2, 2).Trim();
table17.BPSTATE_CODE = lines7[i].Substring(4, 2).Trim();
table17.BPBILL_CODE = lines7[i].Substring(6, 2).Trim();
table17.BPRECORD_TYPE = lines7[i].Substring(28, 1).Trim();
table17.BPBILL_PLAN_DESCRIPTION = lines7[i].Substring(31).TrimEnd();
table17Input.Add(table17);
//adds all table5 list instances to the list table5input
string datconnectionString5 = "Data Source=SWDB10DSQL;Initial Catalog=BillingUI;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework";
using (SqlConnection _datcon5 = new SqlConnection(datconnectionString5))
{
_datcon5.Open();
//opens the predefined connection _con
string datinsertString5 = @"INSERT INTO BILL_PLAN_DESCRIPTION
(BPTABLE_NUMBER, BPCOMPANY, BPSTATE_CODE, BPBILL_CODE, BPRECORD_TYPE, BPBILL_PLAN_DESCRIPTION)
VALUES(@BPTABLE_NUMBER, @BPCOMPANY, @BPSTATE_CODE, @BPBILL_CODE, @BPRECORD_TYPE, @BPBILL_PLAN_DESCRIPTION)";
//defines the sql insert query to be performed
using (SqlCommand datcmd5 = new SqlCommand(datinsertString5, _datcon5))
{
datcmd5.Parameters.Add("@BPTABLE_NUMBER", SqlDbType.NChar);
datcmd5.Parameters.Add("@BPCOMPANY", SqlDbType.NChar);
datcmd5.Parameters.Add("@BPSTATE_CODE", SqlDbType.NChar);
datcmd5.Parameters.Add("@BPBILL_CODE", SqlDbType.NChar);
datcmd5.Parameters.Add("@BPRECORD_TYPE", SqlDbType.NChar);
datcmd5.Parameters.Add("@BPBBILL_PLAN_DESCRIPTION", SqlDbType.NVarChar);
datcmd5.Parameters["@BPTABLE_NUMBER"].Value = table17.BPTABLE_NUMBER;
//adds the list fields and their values to the sql command
datcmd5.Parameters["@BPCOMPANY"].Value = table17.BPCOMPANY;
datcmd5.Parameters["@BPSTATE_CODE"].Value = table17.BPSTATE_CODE;
datcmd5.Parameters["@BPBILL_CODE"].Value = table17.BPBILL_CODE;
datcmd5.Parameters["@BPRECORD_TYPE"].Value = table17.BPRECORD_TYPE;
datcmd5.Parameters["@BPBILL_PLAN_DESCRIPTION"].Value = table17.BPBILL_PLAN_DESCRIPTION;
datcmd5.ExecuteNonQuery();
//executes to insert query
_datcon5.Close();
//closes the no longer in use database connection
}
}
}
}
答案 0 :(得分:1)
您可以在查询中将参数定义为:
@BPBILL_PLAN_DESCRIPTION
您可以将其包含在参数中:
@BPBBILL_PLAN_DESCRIPTION
名称需要完全匹配,它们不能相似。
答案 1 :(得分:1)
看起来你在这里拼错了它:
datcmd5.Parameters.Add(“@ BPBBILL_PLAN_DESCRIPTION”,SqlDbType.NVarChar);
注意额外的B