我在查询分析器里创建军了存储过程。为何在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);
到底那里出问题了?急啊。弄了几天了?
其中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);
到底那里出问题了?急啊。弄了几天了?
你得加上双引号啊 "selectVideoInfo1 "
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();
{
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;
}
这个是否有值。怎么单步跟踪。我设了断点,什么值都没有。
{
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;
}
再跟SQL查询分析器做对比。 应该是你之前的逻辑有问题吧。
改成ps.DataSource=ds.Tables[0].DefaultView;
结贴了,谢谢你们热心的帮助。
<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);
修改一下看看吧