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. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VB Programmer
    Replies:
    0
    Views:
    711
    VB Programmer
    Apr 7, 2004
  2. Jim Bancroft
    Replies:
    4
    Views:
    9,245
    Saravana
    Jan 6, 2005
  3. Replies:
    4
    Views:
    13,936
  4. COHENMARVIN
    Replies:
    1
    Views:
    582
    =?Utf-8?B?U3JlZWppdGggUmFtKE1DU0QuTkVUKQ==?=
    Oct 14, 2005
  5. Michael
    Replies:
    0
    Views:
    368
    Michael
    Nov 16, 2005
Loading...

Share This Page