我在Page_Load事件中写:
        Dim strConn As String
        Dim selectcommand As SqlClient.SqlDataAdapter
        Dim ds As DataSet
        Dim strUsername as string        strUsername=Session("user")
        strConn = ConfigurationManager.AppSettings("SQLConnString")
        conn2 = New SqlClient.SqlConnection(strConn)
        If conn2.State = ConnectionState.Closed Then
            conn2.Open()
        End If
        selectcommand = New SqlClient.SqlDataAdapter("select * from contestregist where username='" + strUsername + "'", conn2)
        ds = New DataSet
        selectcommand.Fill(ds)
        school.Text = ds.Tables(0).Rows(0).Item(2).ToString
系统就报错
而我把上述代码写到一个按钮中就没有任何问题,这是为什么
请问我想在页面加载后就将满足条件的数据显示出来而不需要点击任何按钮,该如何实现,望指教,谢谢

解决方案 »

  1.   

    当然可以
    if(!IsPostBack)
     BindData();
    加try catch单步看看什么错误
      

  2.   

    打个断点看看就一切明白了。把生成的SQL语句放到数据库查询下,检查数据库适配器是否生成正确
      

  3.   

    不能,在Page_Load中连接数据库会导致本机硬盘被格式化Page_Load 是事件, Button1_Click 也是事件, 凭什么能在 Button1_Click中写的东西不能在Page_Load中写呢?
      

  4.   

    完全可以,比如在PAGE——LOAD中给<asp:dropdownlist>加载数据库的值if(!ispostback)
      

  5.   

    都可以的啊,不知道你报的什么错误,我大概看了下你的代码,问题可能出在你的session取值代码
      

  6.   

    绝对可以!
    注意加上
    if(!IsPostBack)
      

  7.   

    为什么不说 报什么错school.Text = ds.Tables(0).Rows(0).Item(2).ToString你确定 ds里面返回的table 不为空? 并且 里面的rows不为空?
      

  8.   

    是不是session的值为空。或者根本没定义!