gpt4 book ai didi

c# - System.IndexOutOfRangeException

转载 作者:行者123 更新时间:2023-12-03 09:09:59 24 4
gpt4 key购买 nike

我想在文本框中显示数据库中的某些列。运行代码时,@ApplicantUsername出现错误

IndexOutOfRangeException



这是我的代码:
        cs.Open();
SqlCommand cmd = new SqlCommand("SELECT ApplicantUsername, Branch, DescriptionOfHouse, DescritpionOfHouseType, LivingCondition, MembersOfHousehold, RealProperty, PersonalProperty, Collaterals, PurposeOfLoan, LoanDesired, MaxLoanVal, PromisoryNoteVal, MonthlyInstallment1, Terms, TotalMonthlyIncome, TotalMonthlyExpenses, Class, NarrativeReport FROM CustomerCreditReport WHERE ApplicantUsername = '" + uname + "'", cs);
SqlDataReader reader = cmd.ExecuteReader();

while (reader.Read())
{
txtUsername.Text = reader["@ApplicantUsername"].ToString();
txtBranch.Text = reader["@Branch"].ToString();
txtDesc.Text = reader["@DescriptionOfHouse"].ToString();
txtOAR.Text = reader["@DescritpionOfHouseType"].ToString();
txtCond.Text = reader["@LivingCondition"].ToString();
txtMem.Text = reader["@MembersOfHousehold"].ToString();
txtReal.Text = reader["@RealProperty"].ToString();
txtPersonal.Text = reader["@PersonalProperty"].ToString();
txtCollateral.Text = reader["@Collaterals"].ToString();
txtPurpose.Text = reader["@PurposeOfLoan"].ToString();
txtDesired.Text = reader["@LoanDesired"].ToString();
txtMLV.Text = reader["@MaxLoanVal"].ToString();
txtPNV.Text = reader["@PromisoryNoteVal"].ToString();
txtMI.Text = reader["@MonthlyInstallment1"].ToString();
txtTerms.Text = reader["@Terms"].ToString();
txtTotIncome.Text = reader["@TotalMonthlyIncome"].ToString();
txtTotExpenses.Text = reader["@TotalMonthlyExpenses"].ToString();
txtClass.Text = reader["@Class"].ToString();
txtNarrative.Text = reader["@NarrativeReport"].ToString();
}
cs.Close();

您能帮我找到解决此问题的方法吗?谢谢。

最佳答案

从所有这些字段名称中删除@

您将@用于添加到参数化查询中的参数(示例中没有参数)。要像这样从列中检索值,请勿使用@,而应使用列的纯名称。

关于c# - System.IndexOutOfRangeException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33796715/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com