Home All Groups Group Topic Archive Search About
Author
13 Jan 2009 9:45 PM
MXC
I am new to ASP.NET

I did a simple test for set datasource.
I put a textbox, a button ans a gridview in a page
I put following code i button_click event.
It not working, Why???
I tried same code in windowsApplication(using datagridview in stead of
gridView) and working fine.

Why not working in webcontrol?


Thanks

  Protected Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
        Dim CustomerID As String
        Dim strConn As String = "Data Source=MXC-PC;Initial
Catalog=Northwind;Integrated Security=True"
        Dim conn As New System.Data.SqlClient.SqlConnection(strConn)
        Dim da As New System.Data.SqlClient.SqlDataAdapter
        Dim ds = New System.Data.DataSet 'Me.dataSet1
        If conn.State = Data.ConnectionState.Closed Then conn.Open()
        Try
            CustomerID = (TextBox1.Text)
            Dim SQL As String = "dbo.CustOrderHist" '& CustomerID
            Dim cmd As New SqlCommand
            cmd.CommandText = SQL
            cmd.Connection = conn
            cmd.CommandType = Data.CommandType.StoredProcedure
            cmd.Parameters.AddWithValue("@CustomerID", CustomerID)
            da.SelectCommand = cmd
            da.Fill(ds)
            GridView1.DataSource = Nothing
            GridView1.DataSource = ds.Tables(0).DefaultView
            DataList1.DataSource = ds
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        conn.Close()
    End Sub