首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

sqldatasource控件给存储过程传参有关问题

2012-10-12 
sqldatasource控件给存储过程传参问题前台代码:string kssj TextBox2.Textstring jssj TextBox4.Text

sqldatasource控件给存储过程传参问题
前台代码:
  string kssj = TextBox2.Text;
  string jssj = TextBox4.Text;
  SqlDataSource1.ConnectionString = "Data Source=LJ-PC\\SQLEXPRESS;Initial Catalog=StudyRoom;Integrated Security=True";
  SqlDataSource1.SelectCommandType = SqlDataSourceCommandType.StoredProcedure;
  SqlDataSource1.SelectCommand = "datasum_proc";
  SqlDataSource1.SelectParameters.Add("@p_kssj", TypeCode.String, kssj);
  SqlDataSource1.SelectParameters.Add("@p_jssj", TypeCode.String, jssj);
  GridView1.DataSource = SqlDataSource1;
  SqlDataSource1.DataBind();
  GridView1.DataBind();

数据库存储过程:
create proc datasum_proc
@p_kssj varchar(10),
@p_jssj varchar(10)

as

select * from table where kssj between @p_kssj and @p_jssj

return 0



运行vs2005下该页面的时候 一直提示 未提供参数 @p_kssj

[解决办法]

SqlDataSource1.DataBind();
GridView1.DataSource = SqlDataSource1;

换下顺序

或者
SqlConnection connection = new SqlConnection("Data Source=LJ-PC\\SQLEXPRESS;Initial Catalog=StudyRoom;Integrated Security=True");
connection.Open();
SqlCommand command = new SqlCommand("datasum_proc", connection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("@p_kssj", kssj);
command.Parameters.AddWithValue("@p_jssj", jssj);
SqlDataReader reader = command.ExecuteReader();
GridView1.DataSource = reader ;
GridView1.DataBind();

热点排行