Set DataSource

Discussion in 'ASP .Net Web Controls' started by MXC, Jan 13, 2009.

  1. MXC

    MXC Guest

    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
     
    MXC, Jan 13, 2009
    #1
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.