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" />