data grid 4Guysfromrolla question

Last post 01-06-2006 6:43 PM by azamsharp. 1 replies.

Sort Posts:

  • data grid 4Guysfromrolla question

    01-06-2006, 6:09 PM
    • Member
      120 point Member
    • Kenn_rosie@msn.com
    • Member since 03-04-2005, 12:22 PM
    • Florissant Colorado
    • Posts 24

    I am trying to do a tutorial from http://aspnet.4guysfromrolla.com/articles/040502-1.aspx which recommended this site.

    Not using the tutorial, I can create a datagid after setting up a SqlDataadapter, generating a data set and entering this code on the page load event:

    Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoad.Click

     

    dsAuthors.Clear()

     

    SqlDataAdapter1.Fill(dsAuthors)

     

    DataGrid1.DataBind()

     

    It works fine.

     

     

    What I am having trouble with is the tutorial that appears to be using a stored procedure.

     

    The tutorial just shows the code to enter but that is it.

     

    My question:

    1. Is the tutorial missing something to tell me?

    2. Should I just keep creating the way I am?

    3.How does that code they show (in Grey) know what data to call from the db?

    4. Is that all the code needed for a sqlconnection?

     

     

     

    Here is the code from the tutorial.... may make more since if you can go to

    http://aspnet.4guysfromrolla.com/articles/040502-1.aspx 

     

    <% @Import Namespace="System.Data" %>
    <% @Import Namespace="System.Data.SqlClient" %>
    <script language="vb" runat="server">
      Sub Page_Load(sender as Object, e as EventArgs)
        BindData()
      End Sub	
    	
      Sub BindData()
        '1. Create a connection
        Dim myConnection as New SqlConnection(
              ConfigurationSettings.AppSettings("connectionString"))
    
        '2. Create the command object, passing in the SQL string
        Const strSQL as String = "sp_Popularity"
        Dim myCommand as New SqlCommand(strSQL, myConnection)
    
        'Set the datagrid's datasource to the datareader and databind
        myConnection.Open()
        dgPopularFAQs.DataSource = myCommand.ExecuteReader(
                                  CommandBehavior.CloseConnection)
        dgPopularFAQs.DataBind()	
      End Sub
    </script>
    
    <asp:datagrid id="dgPopularFAQs" runat="server" />
    

     

     

  • Re: data grid 4Guysfromrolla question

    01-06-2006, 6:43 PM
    • All-Star
      23,606 point All-Star
    • azamsharp
    • Member since 06-11-2003, 5:36 AM
    • Houston,Texas
    • Posts 4,519
    • TrustedFriends-MVPs
    Well, I think the only thing missing is the stored procedure. Everything else looks good.
    HighOnCoding
    Get high on ASP.NET articles, videos, podcasts and more!
Page 1 of 1 (2 items)