【发布时间】:2019-03-24 16:39:45
【问题描述】:
我在尝试数据源的 InsertCommand 时收到以下错误消息:
过程或函数“student_insert”需要参数“@password”,但未提供。
我在 ASCX 页面中设置了大部分参数,除了“密码”,因为我需要在将其保存到数据库之前对其进行一些操作:
<InsertParameters>
<asp:Parameter Name="email" Type="String" />
<asp:Parameter Name="first_name" Type="String" />
<asp:Parameter Name="last_name" Type="String" />
<asp:Parameter Name="university" Type="String" />
<asp:Parameter Name="program" Type="String" />
<asp:Parameter Name="student_number" Type="String" />
<asp:ControlParameter Name="graduation_date" Type="DateTime" ControlID="ctl00$ContentPlaceHolder$ctl01$frmStudents$txtGradDate" PropertyName="Text" />
<asp:ControlParameter Name="student_card_image_name" Type="String" ControlID="ctl00$ContentPlaceHolder$ctl01$frmStudents$FUStudent" PropertyName="FileName" />
<asp:ControlParameter Name="id_card_image_name" Type="String" ControlID="ctl00$ContentPlaceHolder$ctl01$frmStudents$FUID" PropertyName="FileName" />
</InsertParameters>
C#:
protected void datasource_Inserting(object sender, SqlDataSourceCommandEventArgs e) {
ASCIIEncoding encoding = new ASCIIEncoding();
ControlParameter cp = new ControlParameter("@password", DbType.Binary, "ctl00$ContentPlaceHolder$ctl01$frmStudents$txtPassword", "Text");
FormView frmStudents = (FormView)FindControl("frmStudents");
TextBox txtPassword = (TextBox)(frmStudents.FindControl("txtPassword"));
datasource.InsertParameters.Add("password", DbType.Binary, encoding.GetBytes(Cryptogrpahy.Encrypt(txtPassword.Text, basepage.crypt_password)).ToString());
}
当我使用调试器执行该方法时,我看到了我的整个 InsertParameters,带有值...
另外,顺便说一句,由于 DB 类型,我不确定这是否会成功执行,因为我通常在常规 SQLParamater 中使用 VarBinary。
【问题讨论】:
标签: c# asp.net sql-server datasource