Unfortunatly, as is the way with these things, the code runs superbly
<grin> on my development machine. I am trying deploy it as my first
asp.net application and on the live server is the bombing.
I apologize for the length of this message, but if you ask for code, you
get code
Anyway, here is the HTML:
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="frmSessions.aspx.vb"
Inherits="LakeFrontParkAssisstant.frmSessions"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>frmSessions</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="
http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body>
<A href="LFPAHome.htm">Go Home!</A>
<form id="Form1" method="post" runat="server">
<table cols="3" align="left">
<tr>
<td align="left" colSpan="3"><asp:label id="lblPageHeader"
runat="server" Font-Size="Large">Session
Maintenance</asp:label></THEAD></td>
</tr>
<tr>
<td align="left" colSpan="3"><asp:datagrid id="dgSessions"
runat="server" Font-Size="Small" AutoGenerateColumns="False"
AllowPaging="True"
PageSize="6" AllowSorting="True" BackColor="White"
Font-Names="Arial" HorizontalAlign="Left" BorderColor="#999999"
BorderStyle="None" BorderWidth="1px" CellPadding="3"
GridLines="Vertical" ShowFooter="True">
<SelectedItemStyle Font-Size="Small" Font-Names="Arial"
Font-Bold="True" HorizontalAlign="Left" ForeColor="White"
BackColor="#008A8C"></SelectedItemStyle>
<EditItemStyle Font-Size="Small" Font-Names="Arial"
HorizontalAlign="Left" ForeColor="Black"
BackColor="Aquamarine"></EditItemStyle>
<AlternatingItemStyle Font-Size="Small" Font-Names="Arial"
HorizontalAlign="Left" BackColor="Gainsboro"></AlternatingItemStyle>
<ItemStyle Font-Size="Small" Font-Names="Arial"
HorizontalAlign="Left" ForeColor="Black"
BackColor="#EEEEEE"></ItemStyle>
<HeaderStyle Font-Size="Medium" Font-Names="Arial"
Font-Bold="True" HorizontalAlign="Left" ForeColor="White"
BackColor="#000084"></HeaderStyle>
<FooterStyle ForeColor="Black" BackColor="#CCCCCC"></FooterStyle>
<Columns>
<asp:ButtonColumn Text="Insert"
CommandName="Insert"></asp:ButtonColumn>
<asp:EditCommandColumn ButtonType="LinkButton"
UpdateText="Update" CancelText="Cancel"
EditText="Edit"></asp:EditCommandColumn>
<asp:ButtonColumn Text="Delete"
CommandName="Delete"></asp:ButtonColumn>
<asp:BoundColumn Visible="False" DataField="sessionid"
SortExpression="sessionid" HeaderText="Session ID"></asp:BoundColumn>
<asp:BoundColumn DataField="sessionname"
SortExpression="sessionname" HeaderText="Session
Name"></asp:BoundColumn>
<asp:BoundColumn DataField="begindate"
SortExpression="begindate" HeaderText="Begin Date"
DataFormatString="{0:MM-dd-yyyy}"></asp:BoundColumn>
<asp:BoundColumn DataField="enddate" SortExpression="enddate"
HeaderText="End Date"
DataFormatString="{0:MM-dd-yyyy}"></asp:BoundColumn>
</Columns>
<PagerStyle ForeColor="Black" BackColor="#999999"
Mode="NumericPages"></PagerStyle>
</asp:datagrid></td>
</tr>
<tr>
<td align="left" colSpan="3"><asp:label id="lblWhatsUp"
style="Z-INDEX: 101" runat="server" Font-Size="Medium"></asp:label></td>
</tr>
<tr>
<td align="left"><asp:label id="lblSessionName" style="Z-INDEX:
110" runat="server">Session Name:</asp:label></td>
<td align="left"><asp:label id="lblBeginDate" style="Z-INDEX: 111"
runat="server">Begin Date:</asp:label></td>
<td align="left"><asp:label id="lblEndDate" style="Z-INDEX: 113"
runat="server">End Date:</asp:label></td>
</tr>
<tr>
<td align="left"><asp:textbox id="txtSessionName" style="Z-INDEX:
102" runat="server"></asp:textbox></td>
<td align="left"><asp:textbox id="txtBeginDate" style="Z-INDEX:
103" runat="server"></asp:textbox></td>
<td align="left"><asp:textbox id="txtEndDate" style="Z-INDEX: 104"
runat="server"></asp:textbox></td>
</tr>
<tr>
<td align="left" colSpan="3"><asp:button id="btnDo"
runat="server"></asp:button></td>
</tr>
<tr>
<td align="left" colSpan="3"><asp:label id="lblSessionID"
style="Z-INDEX: 106" runat="server"
Visible="False"></asp:label><asp:label id="lblSQLWhere" style="Z-INDEX:
109" runat="server" Visible="False"></asp:label><asp:label
id="lblSQLSortCol" style="Z-INDEX: 107" runat="server"
Visible="False">sessionid</asp:label><asp:label id="lblSQLSortDir"
runat="server" Visible="False">ASC</asp:label></td>
</tr>
</table>
</form>
</body>
</HTML>
Followed by the code behind:
Public Class frmSessions
Inherits System.Web.UI.Page
Protected conString As New
SqlClient.SqlConnection("user=myuser;password=mypassword;server=myserver
;database=mydatabase")
Protected SQLStmt As String
Protected SQLSort As String
Protected SQLWhere As String
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
End Sub
Protected WithEvents dgSessions As
System.Web.UI.WebControls.DataGrid
Protected WithEvents txtEndDate As System.Web.UI.WebControls.TextBox
Protected WithEvents lblWhatsUp As System.Web.UI.WebControls.Label
Protected WithEvents lblSessionID As System.Web.UI.WebControls.Label
Protected WithEvents lblSQLSortCol As
System.Web.UI.WebControls.Label
Protected WithEvents lblSQLSortDir As
System.Web.UI.WebControls.Label
Protected WithEvents lblSQLWhere As System.Web.UI.WebControls.Label
Protected WithEvents lblSessionName As
System.Web.UI.WebControls.Label
Protected WithEvents lblBeginDate As System.Web.UI.WebControls.Label
Protected WithEvents lblEndDate As System.Web.UI.WebControls.Label
Protected WithEvents txtBeginDate As
System.Web.UI.WebControls.TextBox
Protected WithEvents txtSessionName As
System.Web.UI.WebControls.TextBox
Protected WithEvents btnDo As System.Web.UI.WebControls.Button
Protected WithEvents lblPageHeader As
System.Web.UI.WebControls.Label
'NOTE: The following placeholder declaration is required by the Web
Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
SQLStmt = "SELECT sessionid, sessionname, begindate, enddate
FROM lfp_sessions"
SQLSort = " ORDER BY " & lblSQLSortCol.Text & " " &
lblSQLSortDir.Text
SQLWhere = ""
If Not Page.IsPostBack Then
BindData()
End If
'setup gui
GUI("Hide")
End Sub
#Region " Data Grid Events "
Private Sub dgSessions_ItemCommand(ByVal source As Object, ByVal e
As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
dgSessions.ItemCommand
'e.Item is the row of the table where the button was clicked.
Try
'choose button type
Select Case e.CommandName
Case Is = "Sort"
Case Is = "Select"
Case Is = "Insert"
GUI("Clear")
lblWhatsUp.Text = "Adding Item: "
LoadTextBoxes(e)
btnDo.Text = "Insert Record"
GUI("Show")
Case Is = "Edit"
Case Is = "Delete"
Case Is = "Page"
End Select
Catch Exc As Exception
'Process exception and return.
'Dim log As System.Diagnostics.EventLog = New
System.Diagnostics.EventLog
'log.Source = "My Application"
'log.WriteEntry(Exc.ToString())
'Console.WriteLine("Exception of type {0} occurred.",
exc.GetType().ToString())
Finally
End Try
End Sub
Private Sub dgSessions_DeleteCommand(ByVal source As Object, ByVal e
As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
dgSessions.DeleteCommand
GUI("Clear")
lblWhatsUp.Text = "Deleting Item: "
lblSessionID.Text = e.Item.Cells(3).Text
LoadTextBoxes(e)
btnDo.Text = "Delete Record"
GUI("Show")
End Sub
Private Sub dgSessions_EditCommand(ByVal source As Object, ByVal e
As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
dgSessions.EditCommand
GUI("Clear")
lblWhatsUp.Text = "Editing Item: "
lblSessionID.Text = e.Item.Cells(3).Text
LoadTextBoxes(e)
btnDo.Text = "Submit Changes"
GUI("Show")
End Sub
Private Sub dgSessions_PageIndexChanged(ByVal source As Object,
ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs)
Handles dgSessions.PageIndexChanged
GUI("Clear")
dgSessions.CurrentPageIndex = e.NewPageIndex
BindData()
End Sub
Private Sub dgSessions_SortCommand(ByVal source As Object, ByVal e
As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles
dgSessions.SortCommand
If lblSQLSortCol.Text = e.SortExpression Then
Select Case lblSQLSortDir.Text
Case Is = "ASC"
lblSQLSortDir.Text = "DESC"
Case Is = "DESC"
lblSQLSortDir.Text = "ASC"
End Select
Else
lblSQLSortCol.Text = e.SortExpression
lblSQLSortDir.Text = "ASC"
End If
SQLSort = " ORDER BY " & lblSQLSortCol.Text & " " &
lblSQLSortDir.Text
BindData()
End Sub
#End Region
#Region " Data Handling "
Sub BindData()
Dim myDataAdapter As SqlClient.SqlDataAdapter
Dim myDataSet As New DataSet
Try
myDataAdapter = New SqlClient.SqlDataAdapter(SQLStmt &
SQLWhere & SQLSort, conString)
myDataAdapter.Fill(myDataSet, "lfp_sessions")
Dim dv As New DataView
dv = myDataSet.Tables("lfp_sessions").DefaultView
dgSessions.DataSource = dv
dgSessions.DataBind()
Catch Exc As System.OverflowException
Finally
End Try
End Sub
Sub DeleteData()
Dim myDataAdapter As SqlClient.SqlDataAdapter
Dim myDataSet As New DataSet
Try
myDataAdapter = New SqlClient.SqlDataAdapter(SQLStmt &
SQLWhere & SQLSort, conString)
myDataAdapter.Fill(myDataSet, "lfp_sessions")
myDataAdapter.DeleteCommand = New
SqlClient.SqlCommand("DELETE FROM lfp_sessions WHERE (sessionid =
@Original_sessionid)", conString)
myDataAdapter.DeleteCommand.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@original_sessionid",
System.Data.SqlDbType.Int, 4)).Value = lblSessionID.Text
myDataSet.Tables(0).AcceptChanges()
Dim myDataRow As DataRow = myDataSet.Tables(0).Rows(0)
myDataRow.Delete()
myDataAdapter.Update(myDataSet.Tables(0))
Catch Exc As System.OverflowException
Finally
End Try
End Sub
Sub EditData()
Dim myDataAdapter As SqlClient.SqlDataAdapter
Dim myDataSet As New DataSet
Try
myDataAdapter = New SqlClient.SqlDataAdapter(SQLStmt &
SQLWhere & SQLSort, conString)
myDataAdapter.Fill(myDataSet, "lfp_sessions")
myDataAdapter.UpdateCommand = New
SqlClient.SqlCommand("UPDATE lfp_sessions SET sessionname =
@sessionname, begindate = @begindate, enddate = @enddate WHERE
(sessionid = @Original_sessionid)", conString)
myDataAdapter.UpdateCommand.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@original_sessionid",
System.Data.SqlDbType.Int, 4)).Value = lblSessionID.Text
myDataAdapter.UpdateCommand.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@sessionname",
System.Data.SqlDbType.VarChar, 50, "sessionname"))
myDataAdapter.UpdateCommand.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@begindate",
System.Data.SqlDbType.DateTime, 8, "begindate"))
myDataAdapter.UpdateCommand.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@enddate",
System.Data.SqlDbType.DateTime, 8, "enddate"))
myDataSet.Tables(0).AcceptChanges()
Dim myDataRow As DataRow = myDataSet.Tables(0).Rows(0)
myDataRow = FillRow(myDataRow)
myDataAdapter.Update(myDataSet.Tables(0))
Catch Exc As System.OverflowException
Finally
End Try
End Sub
Sub InsertData()
Dim myDataAdapter As SqlClient.SqlDataAdapter
Dim myDataSet As New DataSet
Try
myDataAdapter = New SqlClient.SqlDataAdapter(SQLStmt,
conString)
myDataAdapter.Fill(myDataSet, "lfp_sessions")
myDataAdapter.InsertCommand = New
SqlClient.SqlCommand("INSERT INTO lfp_sessions(sessionname, begindate,
enddate) VALUES (@sessionname, @begindate, @enddate)")
myDataAdapter.InsertCommand.Connection = conString
myDataAdapter.InsertCommand.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@sessionname",
System.Data.SqlDbType.VarChar, 50, "sessionname"))
myDataAdapter.InsertCommand.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@begindate",
System.Data.SqlDbType.DateTime, 8, "begindate"))
myDataAdapter.InsertCommand.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@enddate",
System.Data.SqlDbType.DateTime, 8, "enddate"))
Dim myDataRow As DataRow = myDataSet.Tables(0).NewRow()
myDataRow = FillRow(myDataRow)
myDataSet.Tables(0).Rows.Add(myDataRow)
myDataAdapter.Update(myDataSet.Tables(0))
Catch Exc As System.OverflowException
Finally
End Try
End Sub
Function FillRow(ByVal dr As DataRow)
dr("sessionname") = txtSessionName.Text
dr("begindate") = txtBeginDate.Text
dr("enddate") = txtEndDate.Text
Return dr
End Function
#End Region
Private Sub btnDo_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnDo.Click
Try
Dim SQLTemp As String = SQLWhere
Select Case btnDo.Text
Case Is = "Insert Record"
SQLWhere = " WHERE sessionid = '" &
lblSessionID.Text & "'"
InsertData()
SQLWhere = SQLTemp
BindData()
Case Is = "Submit Changes"
SQLWhere = " WHERE sessionid = '" &
lblSessionID.Text & "'"
EditData()
SQLWhere = SQLTemp
BindData()
Case Is = "Delete Record"
SQLWhere = " WHERE sessionid = '" &
lblSessionID.Text & "'"
DeleteData()
SQLWhere = SQLTemp
If dgSessions.CurrentPageIndex >=
(dgSessions.PageCount - 1) Then
dgSessions.CurrentPageIndex = 0
BindData()
dgSessions.CurrentPageIndex =
(dgSessions.PageCount - 1)
End If
BindData()
End Select
Catch Exc As System.OverflowException
Finally
'handle GUI
GUI("Hide")
GUI("Clear")
End Try
End Sub
Private Sub GUI(ByVal strAction As String)
Try
Select Case strAction
Case Is = "Hide"
lblWhatsUp.Visible = False
lblSessionName.Visible = False
txtSessionName.Visible = False
txtBeginDate.Visible = False
lblBeginDate.Visible = False
txtEndDate.Visible = False
lblEndDate.Visible = False
btnDo.Visible = False
Case Is = "Show"
lblWhatsUp.Visible = True
lblSessionName.Visible = True
txtSessionName.Visible = True
lblBeginDate.Visible = True
txtBeginDate.Visible = True
lblEndDate.Visible = True
txtEndDate.Visible = True
btnDo.Visible = True
Case Is = "Clear"
lblWhatsUp.Text = ""
lblSessionID.Text = ""
txtSessionName.Text = ""
txtBeginDate.Text = ""
txtEndDate.Text = ""
btnDo.Text = ""
End Select
Catch Exc As System.OverflowException
Finally
End Try
End Sub
Private Sub LoadTextBoxes(ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs)
If e.Item.Cells(4).Text <> " " Then txtSessionName.Text =
e.Item.Cells(4).Text
If e.Item.Cells(5).Text <> " " Then txtBeginDate.Text =
e.Item.Cells(5).Text
If e.Item.Cells(6).Text <> " " Then txtEndDate.Text =
e.Item.Cells(6).Text
End Sub
End Class
Steve Hoyer