我已经创建了小型学生页面,我为课外添加了下拉列表。
所以我做了以下事情:
这是来自Ecurricular表的screenshot表数据
claimattachment
ASPX标记:
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = Connection.DBconnection();
SqlCommand com = new SqlCommand("sp_insertextracurricular", con);
com.CommandType = CommandType.StoredProcedure;
com.Parameters.AddWithValue("@id", extracurricular.Text.Trim());
com.Parameters.AddWithValue("@extracurricular", Textcurricular.Text.Trim());
SqlDataAdapter adp = new SqlDataAdapter(com);
DataSet ds = new DataSet();
adp.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
extracurricular.Text = ds.Tables[0].Rows[0]["id"].ToString();
Textcurricular.Text = ds.Tables[0].Rows[0]["extracurricular"].ToString();
}
}
存储过程:
<td><asp:HiddenField ID="curricular" runat="server" />
<asp:TextBox ID="extracurricular" runat="server" Visible="false"></asp:TextBox>
</td>
<asp:DropDownList ID="Textcurricular" runat="server" BackColor="#FF0066"
Height="16px" Width="129px"></asp:DropDownList>
当我运行上面的代码时,我收到错误
过程sp_insertextracurricular没有提供参数和参数。
我是.net的新手,我需要在下拉列表中显示Ecurricular数据,我只是对此感到困惑,我可能知道我的代码中的错误是什么吗?
答案 0 :(得分:2)
您已添加参数@id
和@extracurricular
但未将其包含在存储过程中:
ALTER PROCEDURE sp_insertextracurricular
AS
begin
select * from Ecurricular
End
你需要像这样添加它们:
ALTER PROCEDURE sp_insertextracurricular
@id varchar(10),
@extracurricular varchar(200)
AS
begin
select * from Ecurricular
End
我猜这里的列大小/数据类型,你会想要查看这些。
答案 1 :(得分:-1)
这不是.NET问题。您提供的存储过程不接受任何参数,但您在此处创建参数并将其传入。
com.CommandType = CommandType.StoredProcedure;
com.Parameters.AddWithValue("@id", extracurricular.Text.Trim());
com.Parameters.AddWithValue("@extracurricular", Textcurricular.Text.Trim());
错误告诉您不要传递任何内容,因为存储过程不会接受任何操作。
您需要更新存储过程才能获取这些值,因为看起来您最终会将其转换为插入值。
ALTER PROCEDURE sp_insertextracurricular
@id VARCHAR, --<---looks like you are passing a string, make sure to make this what it actually needs to be
@extracurricular VARCHAR
AS
BEGIN
select * from Ecurricular --<---I take it this will become and insert based on Stored Procedure name.
End