谁能解决这个问题(数据列表) [英] can anyone solve this problem (datalist)

查看:50
本文介绍了谁能解决这个问题(数据列表)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

datalist.aspx

protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["dbConnection"].ToString());
        SqlCommand cmd = new SqlCommand();
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.CommandText = "ups_JoinRegistration3";
        //cmd.Parameters.Add("@UserID", SqlDbType.Int);
        cmd.Connection = con;
        con.Open();

        DataTable dt = new DataTable();
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        da.Fill(dt);
        dlProfile.DataSource = dt;
        dlProfile.DataBind();

        cmd.Dispose();
        con.Close();


    }
    protected void dlProfile_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName == "Details")
        {

            Label lb = new Label();
            lb = (Label)e.Item.FindControl("Label2");
            string ID = lb.Text;
            ////string UserId = "";
            //int id = Convert.ToInt32(Request.QueryString["en"].ToString()); 
           
            //string UserId = Convert.ToString(e.CommandArgument);

            Response.Redirect("ViewDetails.aspx?@ID=" + ID);



在datalist.aspx中也



in datalist.aspx also

System.Data.SqlClient.SqlException: Procedure or Function ''ups_JoinRegistration3'' expects parameter ''@ID'', which was not supplied.

此错误

ViewDetails.aspx

this error

ViewDetails.aspx

SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["dbConnection"].ToString());

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            int id = Convert.ToInt32(Request.QueryString["@ID"].ToString());
            //string id = Request.QueryString["en"].ToString();
           
            SqlCommand cmd = new SqlCommand("ups_JoinRegistration3", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@ID", SqlDbType.Int).Value = id;
            cmd.Connection = con;
            con.Open();
            DataTable dt = new DataTable();
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(dt);
            dlProfile.DataSource = dt;
            dlProfile.DataBind();
            cmd.Dispose();
            con.Close();
            
        }




ups_JoinRegistration3




ups_JoinRegistration3

ALTER PROCEDURE [dbo].[ups_JoinRegistration3]
(@ID int)
AS

BEGIN



select * from Registration where ID=@ID
END




登记表




Registration table

ID          int
UserId      int
FirstName   nvarchar(50)
MiddleName  nvarchar(50)
LastName    nvarchar(50)
DateOfBirth nvarchar(50)
Gender      nvarchar(50)
Email       nvarchar(50)
Occupation  nvarchar(50)
State       nvarchar(50)
City        nvarchar(50)
Nationality nvarchar(50)





asp和sp中的错误





Error in asp as well as in sp

System.Data.SqlClient.SqlException: Procedure or Function ''ups_JoinRegistration3'' expects parameter ''@ID'', which was not supplied.




谁能解决并帮助我 谢谢




can any one solve and help me thanks

推荐答案

您好,

很清楚.

您正在将ID作为参数传递给存储过程,因此在执行SP时,它将查找ID

在后面的代码中,您没有提及任何参数(提及但已注释).当它执行您的命令时,它将检查不可用的参数,并给您错误.

从代码后面将ID参数传递给存储过程.

希望这对您有帮助
Hi,

Its quite clear.

You are passing ID as parameter to your stored procedure so when you executing the SP it looks for ID

In your code behind you didn''t mentioned any parameter(mentioned but commented). When it executes your command it will check for the paramter which is not available and will give you the error.

Pass the ID paramater to the stored procedure from code-behind.

Hope this helps


create PROCEDURE [dbo].[ups_JoinRegistration3]  AS 
BEGIN
 select * from Registration 


这篇关于谁能解决这个问题(数据列表)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆