2013年9月25日 星期三

GridView用語法顯示資料


 Protected Sub Page_Load(sender As Object, e As EventArgs)
        bind()
        If Not IsPostBack Then
            bind()
        End If
    End Sub

    Public Sub bind()
        sqlcon = New SqlConnection(strCon)
        Dim sqlstr As String = "select * from dep"
        sqlcon = New SqlConnection(strCon)
        Dim myda As New SqlDataAdapter(sqlstr, sqlcon)
        Dim myds As New DataSet()
        sqlcon.Open()
        myda.Fill(myds, "test")
        GridView1.DataSource = myds
        GridView1.DataKeyNames = New String() {"dep_no"}
        GridView1.DataBind()
        sqlcon.Close()
    End Sub

沒有留言:

張貼留言