private void getArticle() //取得分类文章
{
try
{
SqlConnection conn = new SqlConnection("server=.;database=zznews;uid=sa;pwd=");
conn.Open();
SqlDataAdapter myCommand = new SqlDataAdapter(); //创建SqlDataAdapter 类
myCommand.SelectCommand=new SqlCommand("sp_selCkArticleByClass",conn);
myCommand.SelectCommand.CommandType=CommandType.StoredProcedure ;
SqlParameter classname=myCommand.SelectCommand.Parameters.Add("@classname",SqlDbType.Char,200);
classname.Value = Page.Request["classname"];
DataSet ds=new DataSet(); //建立并填充数据集
myCommand.Fill(ds);
DataGrid1.DataSource=ds;
DataGrid1.DataBind();
lblCurrentIndex.Text="第"+((Int32)DataGrid1.CurrentPageIndex+1)+"页";
lblPageCount.Text="/共"+DataGrid1.PageCount+"页";
conn.Close() ;
}
catch(SqlException e)
{
Console.WriteLine("Exception in Main: " + e.Message); //出错处理
}
}
请着重讲一下红字部分。
{
try
{
SqlConnection conn = new SqlConnection("server=.;database=zznews;uid=sa;pwd=");
conn.Open();
SqlDataAdapter myCommand = new SqlDataAdapter(); //创建SqlDataAdapter 类
myCommand.SelectCommand=new SqlCommand("sp_selCkArticleByClass",conn);
myCommand.SelectCommand.CommandType=CommandType.StoredProcedure ;
SqlParameter classname=myCommand.SelectCommand.Parameters.Add("@classname",SqlDbType.Char,200);
classname.Value = Page.Request["classname"];
DataSet ds=new DataSet(); //建立并填充数据集
myCommand.Fill(ds);
DataGrid1.DataSource=ds;
DataGrid1.DataBind();
lblCurrentIndex.Text="第"+((Int32)DataGrid1.CurrentPageIndex+1)+"页";
lblPageCount.Text="/共"+DataGrid1.PageCount+"页";
conn.Close() ;
}
catch(SqlException e)
{
Console.WriteLine("Exception in Main: " + e.Message); //出错处理
}
}
请着重讲一下红字部分。
解决方案 »
- 怎么给服务器控件循环赋不同的ID号
- 访问网站的问题
- 对于网站后台管理地址的安全性问题讨论
- 如何在一个服务器上建两个网站?
- 两个DropDownList之间如何建立控制的先后关系?(比如先选省份,后才能选城市)
- Infragistics 2005 5.3 控件问题,在拖放入页面后出现提示出错,但控件还是能用。不知为什么?
- 关于同一个服务器下 两个数据库的联合查询的问题,急啊!!
- datagrid模板列初始化显示下拉框,保存后显示下拉框值
- html代码写入数据库却只有第一行数据?!
- 这个同时搜索两个表中的内容的SQL语句正确吗?
- 一条SQL语句,我怎么都想不出~请个位帮忙想想办法
- 如何刪除數據庫裡超過20分鐘的數據
2.知道了 是通过存储过程操作数据库
3.知道了 传递给存储过程的参数是:@classname
4.知道了 classname的值是从页面传递来的["classname"]的值。后面自然就可以用 这个参数去操作数据库了。
myCommand.SelectCommand=new SqlCommand("sp_selCkArticleByClass",conn); /*建立要执行的SQL*/
myCommand.SelectCommand.CommandType=CommandType.StoredProcedure ; /*指明要执行的SQL是存储过程*/
SqlParameter classname=myCommand.SelectCommand.Parameters.Add("@classname",SqlDbType.Char,200); /*为存储过程提供所需要的参数*/
classname.Value = Page.Request["classname"];
这个没有什么特别的.如果你看一个数据中相应的这个存储过程,就发现和直接写SQL语名是一样用的.