我在查询分析器里创建军了存储过程。为何在asp.net里调用时,就报错。当前上下文中不存在名称“selectVideoInfo1”
其中selectVideoInfo1是我创建的存储过程。
代码如下:
查询分析器
CREATE   PROCEDURE   selectVideoInfo1  
@at   NVARCHAR(500)   =   NULL
AS   
select * from videoInfo where videoTitle like '%'+@at+'%'
GO 
asp.net里的代码:SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["con"]);
        con.Open();
        SqlCommand scom = new SqlCommand(selectVideoInfo1, con);
      scom.CommandType = CommandType.StoredProcedure;
        SqlParameter parameterLoginID = new SqlParameter("@at ", SqlDbType.VarChar, 50);
        parameterLoginID.Value =name;
        scom.Parameters.Add(parameterLoginID); 
到底那里出问题了?急啊。弄了几天了?

解决方案 »

  1.   

    SqlCommand scom = new SqlCommand("selectVideoInfo1", con);
      

  2.   

    你在数据库里 用 exec执行 看有没问题
      

  3.   

    selectVideoInfo1 你这个是存取过程名是吧?
     你得加上双引号啊 "selectVideoInfo1 "
      

  4.   

    问题解决了。可是又出现新的问题。在查询分析器里据执行可以查出符合条件的记录,可是在asp.net程序里就查不出?不知怎么回事?
      

  5.   

    string name = Session["txtKeys"].ToString();
            int noncePage = Convert.ToInt32(labPage.Text);
            PagedDataSource ps = new PagedDataSource();
            DataSet ds = operateData.showpro("selectVideoInfo1",name);//新加
            ps.DataSource=ds.Tables["VideoInfo"].DefaultView;
            ps.AllowPaging = true;
            ps.PageSize = 6;
            ps.CurrentPageIndex = noncePage - 1;
            this.lnkbtnFront.Enabled = true;
            this.lnkbtnNext.Enabled = true;
            this.lnkbtnLast.Enabled = true;
            this.lnkbtnFirst.Enabled = true;
            if (noncePage == 1)
            {
                this.lnkbtnFirst.Enabled = false;//不显示第一页按钮
                this.lnkbtnFront.Enabled = false;//不显示上一页按钮
            } if (noncePage == ps.PageCount)
            {
                this.lnkbtnNext.Enabled = false;//不显示下一页
                this.lnkbtnLast.Enabled = false;//不显示最后一页
            }
            labBackPage.Text = Convert.ToString(ps.PageCount);
            DataList1.DataSource = ps;
            DataList1.DataBind();       
      

  6.   

     public static DataSet showpro(string StoreName, string  at)
        {
            SqlConnection con = createCon();
            SqlDataAdapter sdr = new SqlDataAdapter(StoreName, con);
            sdr.SelectCommand.CommandType = CommandType.StoredProcedure;
            SqlParameter para = new SqlParameter("@at", SqlDbType.VarChar,50);
            para.Value = "%"+ at +"%";
            sdr.SelectCommand.Parameters.Add(para);
            con.Open();
            DataSet ds = new DataSet();
            sdr.Fill(ds, "VideoTitle");
            con.Close();
            return ds;
        }
      

  7.   

     ps.DataSource=ds.Tables["VideoInfo"].DefaultView;
    这个是否有值。怎么单步跟踪。我设了断点,什么值都没有。
      

  8.   

    SqlCommand scom = new SqlCommand("selectVideoInfo1", con);
      

  9.   

     public bool ExecuteProceduce(string proceduceName, SqlParameter[] oSqlParam)
            {
                SqlCommand oComm = new SqlCommand(proceduceName, this.Connection);
                oComm.CommandType = CommandType.StoredProcedure;            foreach (SqlParameter oParam in oSqlParam)
                {
                    oComm.Parameters.Add(oParam);
                }
             
                this.Open();
                oComm.ExecuteNonQuery();                this.Close();
                oComm.Dispose();            return true;
            }
      

  10.   

    是看一下scom.Parameters.Add(parameterLoginID);  这个parameterLoginID的值。
    再跟SQL查询分析器做对比。    应该是你之前的逻辑有问题吧。
      

  11.   

    问题解决了。是这句有问题ps.DataSource=ds.Tables["VideoInfo"].DefaultView;
    改成ps.DataSource=ds.Tables[0].DefaultView;
    结贴了,谢谢你们热心的帮助。
      

  12.   

    首先,你的连接字符串有问题,一般连接类
    <appSettings/>
    <connectionStrings>
    <add name="MyConn" connectionString="Data Source=CHINA-129BD748C\SQLEXPRESS;Initial Catalog=PeopleManageSystem;Integrated Security=sspi"/>
    </connectionStrings>
    则连接字符串写成:
    SqlConnection con=new SqlConnection(ConfigurationManager.ConnectionStrings["MyConn"].ConnectionString);
    若连接类中的是
    <appSettings/>
    <connectionStrings>
    <add key="MyConn" connectionString="Data Source=CHINA-129BD748C\SQLEXPRESS;Initial Catalog=PeopleManageSystem;Integrated Security=sspi"/>
    </connectionStrings>
    则连接字符串写成:
    SqlConnection con=new SqlConnection(ConfigurationManager.AppSettings["MyConn"]);
    其次,你command中要用双引号吧存储过程名引起来,即:
    SqlCommand scom = new SqlCommand("selectVideoInfo1", con); 
     
    修改一下看看吧