By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,883 Members | 955 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,883 IT Pros & Developers. It's quick & easy.

please help

P: n/a
I am trying to learn asp.net and build a site and i am using web matrix and
vb.net.

I have installed the MSDE on my windows xp pro, i am using the book
calledbeginning dynamic websites with asp.net web matrix.

My problem is the following:

in the book it talks about connectiong to the PUBS database and i know sql
programming and have worked with sql server but i dont see the pubs database
nor Northwind.

#2 im following the example in the book and building a guestbook and i have
set debug="true" get the following error:

myCommand.Fill(ds)

and it says sql connection has not initialized

please look at this snippet and help me and tell me why its not working when
im not even setting up the strings /web matrix is...

<%@ Page Language="VB" Debug="true" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<script runat="server">

Sub Page_Load(Sender As Object, E As EventArgs)

If Not Page.IsPostBack Then

' Databind the data grid on the first request only
' (on postback, rebind only in paging and sorting commands)

BindGrid()

End If

End Sub

Sub DataGrid_Page(Sender As Object, e As DataGridPageChangedEventArgs)

DataGrid1.CurrentPageIndex = e.NewPageIndex
BindGrid()

End Sub

Sub DataGrid_Sort(Sender As Object, e As DataGridSortCommandEventArgs)

DataGrid1.CurrentPageIndex = 0
SortField = e.SortExpression
BindGrid()

End Sub
'---------------------------------------------------------
'
' Helpers
'
' use a property to keep track of the sort field, and
' save it in viewstate between postbacks

Property SortField() As String

Get
Dim o As Object = ViewState("SortField")
If o Is Nothing Then
Return String.Empty
End If
Return CStr(o)
End Get

Set(ByVal Value As String)
ViewState("SortField") = Value
End Set

End Property

Sub BindGrid()

' TODO: update the ConnectionString value for your application
Dim ConnectionString As String =
"server=(local);database=master;trusted_connection =true"
Dim CommandText As String

' TODO: update the CommandText value for your application
If SortField = String.Empty Then
CommandText = "select Author, Subject, Message, postedDate" & _
"from guestbookentries order by postedDate desc"
Else
CommandText = "select Author, Subject, Message, postedDate" & _
"from guestbookentries order by " & SortField
End If

Dim myConnection As New
SqlConnection(ConfigurationSettings.AppSettings("g uestbookentries"))
Dim myCommand As New SqlDataAdapter(CommandText, myConnection)

Dim ds As New DataSet()
myCommand.Fill(ds)

DataGrid1.DataSource = ds
DataGrid1.DataBind()

End Sub

</script>
<html>
<head>
</head>
<body style="FONT-FAMILY: arial">
<h2>Data Report with Paging and Sorting
</h2>
<hr size="1" />
<form runat="server">
<asp:datagrid id="DataGrid1" runat="server"
AutoGenerateColumns="False" width="80%" CellSpacing="1" GridLines="None"
CellPadding="3" BackColor="White" ForeColor="Black"
OnPageIndexChanged="DataGrid_Page" PageSize="6" AllowPaging="True"
OnSortCommand="DataGrid_Sort" AllowSorting="True">
<HeaderStyle font-bold="True" forecolor="White"
backcolor="#4A3C8C"></HeaderStyle>
<PagerStyle horizontalalign="Right" backcolor="#C6C3C6"
mode="NumericPages"></PagerStyle>
<ItemStyle backcolor="#DEDFDE"></ItemStyle>
<Columns>
<asp:TemplateColumn SortExpression="Author"
HeaderText="Author">
<EditItemTemplate>
<asp:Label id="Label1" runat="server">Label

<%# Container.DataItem("Author")%>
</asp:Label>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn SortExpression="Subject"
HeaderText="Subject">
<EditItemTemplate>
<asp:Label id="Label1" runat="server">Label

<%# Container.DataItem("Subject") %>
</asp:Label>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn SortExpression="Message"
HeaderText="Message">
<EditItemTemplate>
<asp:Label id="Label1" runat="server">Label

<%# Container.DataItem("Message") %>
</asp:Label>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn SortExpression="PostedDate"
HeaderText="postedDate">
<EditItemTemplate>
<asp:Label id="Label1" runat="server">Label
<%# Container.DataItem("postedDate")%>
</asp:Label>
</EditItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
</form>
</body>
</html>

Thanks for your help from this poor programmer
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
The sample SQL Server databases are not installed with MSDE. You need to run
the install scripts for Pubs and Northwind.

You can download these from here
http://www.microsoft.com/downloads/d...displaylang=en
"ntexchange05" wrote:
I am trying to learn asp.net and build a site and i am using web matrix and
vb.net.

I have installed the MSDE on my windows xp pro, i am using the book
calledbeginning dynamic websites with asp.net web matrix.

My problem is the following:

in the book it talks about connectiong to the PUBS database and i know sql
programming and have worked with sql server but i dont see the pubs database
nor Northwind.

#2 im following the example in the book and building a guestbook and i have
set debug="true" get the following error:

myCommand.Fill(ds)

and it says sql connection has not initialized

please look at this snippet and help me and tell me why its not working when
im not even setting up the strings /web matrix is...

<%@ Page Language="VB" Debug="true" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<script runat="server">

Sub Page_Load(Sender As Object, E As EventArgs)

If Not Page.IsPostBack Then

' Databind the data grid on the first request only
' (on postback, rebind only in paging and sorting commands)

BindGrid()

End If

End Sub

Sub DataGrid_Page(Sender As Object, e As DataGridPageChangedEventArgs)

DataGrid1.CurrentPageIndex = e.NewPageIndex
BindGrid()

End Sub

Sub DataGrid_Sort(Sender As Object, e As DataGridSortCommandEventArgs)

DataGrid1.CurrentPageIndex = 0
SortField = e.SortExpression
BindGrid()

End Sub
'---------------------------------------------------------
'
' Helpers
'
' use a property to keep track of the sort field, and
' save it in viewstate between postbacks

Property SortField() As String

Get
Dim o As Object = ViewState("SortField")
If o Is Nothing Then
Return String.Empty
End If
Return CStr(o)
End Get

Set(ByVal Value As String)
ViewState("SortField") = Value
End Set

End Property

Sub BindGrid()

' TODO: update the ConnectionString value for your application
Dim ConnectionString As String =
"server=(local);database=master;trusted_connection =true"
Dim CommandText As String

' TODO: update the CommandText value for your application
If SortField = String.Empty Then
CommandText = "select Author, Subject, Message, postedDate" & _
"from guestbookentries order by postedDate desc"
Else
CommandText = "select Author, Subject, Message, postedDate" & _
"from guestbookentries order by " & SortField
End If

Dim myConnection As New
SqlConnection(ConfigurationSettings.AppSettings("g uestbookentries"))
Dim myCommand As New SqlDataAdapter(CommandText, myConnection)

Dim ds As New DataSet()
myCommand.Fill(ds)

DataGrid1.DataSource = ds
DataGrid1.DataBind()

End Sub

</script>
<html>
<head>
</head>
<body style="FONT-FAMILY: arial">
<h2>Data Report with Paging and Sorting
</h2>
<hr size="1" />
<form runat="server">
<asp:datagrid id="DataGrid1" runat="server"
AutoGenerateColumns="False" width="80%" CellSpacing="1" GridLines="None"
CellPadding="3" BackColor="White" ForeColor="Black"
OnPageIndexChanged="DataGrid_Page" PageSize="6" AllowPaging="True"
OnSortCommand="DataGrid_Sort" AllowSorting="True">
<HeaderStyle font-bold="True" forecolor="White"
backcolor="#4A3C8C"></HeaderStyle>
<PagerStyle horizontalalign="Right" backcolor="#C6C3C6"
mode="NumericPages"></PagerStyle>
<ItemStyle backcolor="#DEDFDE"></ItemStyle>
<Columns>
<asp:TemplateColumn SortExpression="Author"
HeaderText="Author">
<EditItemTemplate>
<asp:Label id="Label1" runat="server">Label

<%# Container.DataItem("Author")%>
</asp:Label>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn SortExpression="Subject"
HeaderText="Subject">
<EditItemTemplate>
<asp:Label id="Label1" runat="server">Label

<%# Container.DataItem("Subject") %>
</asp:Label>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn SortExpression="Message"
HeaderText="Message">
<EditItemTemplate>
<asp:Label id="Label1" runat="server">Label

<%# Container.DataItem("Message") %>
</asp:Label>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn SortExpression="PostedDate"
HeaderText="postedDate">
<EditItemTemplate>
<asp:Label id="Label1" runat="server">Label
<%# Container.DataItem("postedDate")%>
</asp:Label>
</EditItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
</form>
</body>
</html>

Thanks for your help from this poor programmer

Nov 21 '05 #2

P: n/a
Thank you so very much for answering my question, could you please explain
to me why my code fails when it is generated by the web matrix software?
thanks again ..and god bless
"Scott Swigart" <sc***@swigartconsulting.com> wrote in message
news:17**********************************@microsof t.com...
The sample SQL Server databases are not installed with MSDE. You need to run the install scripts for Pubs and Northwind.

You can download these from here:
http://www.microsoft.com/downloads/d...displaylang=en

"ntexchange05" wrote:
I am trying to learn asp.net and build a site and i am using web matrix and vb.net.

I have installed the MSDE on my windows xp pro, i am using the book
calledbeginning dynamic websites with asp.net web matrix.

My problem is the following:

in the book it talks about connectiong to the PUBS database and i know sql programming and have worked with sql server but i dont see the pubs database nor Northwind.

#2 im following the example in the book and building a guestbook and i have set debug="true" get the following error:

myCommand.Fill(ds)

and it says sql connection has not initialized

please look at this snippet and help me and tell me why its not working when im not even setting up the strings /web matrix is...

<%@ Page Language="VB" Debug="true" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<script runat="server">

Sub Page_Load(Sender As Object, E As EventArgs)

If Not Page.IsPostBack Then

' Databind the data grid on the first request only
' (on postback, rebind only in paging and sorting commands)

BindGrid()

End If

End Sub

Sub DataGrid_Page(Sender As Object, e As DataGridPageChangedEventArgs)
DataGrid1.CurrentPageIndex = e.NewPageIndex
BindGrid()

End Sub

Sub DataGrid_Sort(Sender As Object, e As DataGridSortCommandEventArgs)
DataGrid1.CurrentPageIndex = 0
SortField = e.SortExpression
BindGrid()

End Sub
'---------------------------------------------------------
'
' Helpers
'
' use a property to keep track of the sort field, and
' save it in viewstate between postbacks

Property SortField() As String

Get
Dim o As Object = ViewState("SortField")
If o Is Nothing Then
Return String.Empty
End If
Return CStr(o)
End Get

Set(ByVal Value As String)
ViewState("SortField") = Value
End Set

End Property

Sub BindGrid()

' TODO: update the ConnectionString value for your application
Dim ConnectionString As String =
"server=(local);database=master;trusted_connection =true"
Dim CommandText As String

' TODO: update the CommandText value for your application
If SortField = String.Empty Then
CommandText = "select Author, Subject, Message, postedDate" & _ "from guestbookentries order by postedDate desc"
Else
CommandText = "select Author, Subject, Message, postedDate" & _ "from guestbookentries order by " & SortField
End If

Dim myConnection As New
SqlConnection(ConfigurationSettings.AppSettings("g uestbookentries"))
Dim myCommand As New SqlDataAdapter(CommandText, myConnection)

Dim ds As New DataSet()
myCommand.Fill(ds)

DataGrid1.DataSource = ds
DataGrid1.DataBind()

End Sub

</script>
<html>
<head>
</head>
<body style="FONT-FAMILY: arial">
<h2>Data Report with Paging and Sorting
</h2>
<hr size="1" />
<form runat="server">
<asp:datagrid id="DataGrid1" runat="server"
AutoGenerateColumns="False" width="80%" CellSpacing="1" GridLines="None"
CellPadding="3" BackColor="White" ForeColor="Black"
OnPageIndexChanged="DataGrid_Page" PageSize="6" AllowPaging="True"
OnSortCommand="DataGrid_Sort" AllowSorting="True">
<HeaderStyle font-bold="True" forecolor="White"
backcolor="#4A3C8C"></HeaderStyle>
<PagerStyle horizontalalign="Right" backcolor="#C6C3C6"
mode="NumericPages"></PagerStyle>
<ItemStyle backcolor="#DEDFDE"></ItemStyle>
<Columns>
<asp:TemplateColumn SortExpression="Author"
HeaderText="Author">
<EditItemTemplate>
<asp:Label id="Label1" runat="server">Label

<%# Container.DataItem("Author")%>
</asp:Label>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn SortExpression="Subject"
HeaderText="Subject">
<EditItemTemplate>
<asp:Label id="Label1" runat="server">Label

<%# Container.DataItem("Subject") %>
</asp:Label>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn SortExpression="Message"
HeaderText="Message">
<EditItemTemplate>
<asp:Label id="Label1" runat="server">Label

<%# Container.DataItem("Message") %>
</asp:Label>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn SortExpression="PostedDate"
HeaderText="postedDate">
<EditItemTemplate>
<asp:Label id="Label1" runat="server">Label
<%# Container.DataItem("postedDate")%>
</asp:Label>
</EditItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
</form>
</body>
</html>

Thanks for your help from this poor programmer

Nov 21 '05 #3

P: n/a
nTextChange,

If you have VisualStudio Net there is in my opinion not any reason to use
Matrix. Matrix looks at least as a subset of VisualStudio Net

The design part from AspNet in Visual.Studio Net before 2005 is real weak.

Therefore you can (if you are not somebody who uses direct HTML) go for a
more Webpage designer program beside that.

I hope this gives an idea

Cor
Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.