B
Biva
Hello All,
Please help. I get the following error from my webpage:
System.InvalidCastException: Specified cast is not valid.
at Time.MaintAtRiskProjects.UpdateProject(String Project, String
AtRiskCode, String Comment)
Code for UpdateProject(String Project, String AtRiskCode, String Comment)
is:
Private Sub UpdateProject(ByVal Project As String, ByVal AtRiskCode As
String, ByVal Comment As String)
Try
Dim strProject As String = Trim(Project)
Dim strAtRiskCode As String = Trim(AtRiskCode)
Dim strComment As String = Trim(Comment)
Dim r As AtRiskProjectsDS.AtRiskProjectsRow
Dim rows() As AtRiskProjectsDS.AtRiskProjectsRow =
AtRiskProjDS.AtRiskProjects.Select(AtRiskProjDS.AtRiskProjects.ProjectColumn.ColumnName
& "= '" & strProject & "' AND " &
AtRiskProjDS.AtRiskProjects.AtRiskCodeColumn.ColumnName & "= '" &
strAtRiskCode & "' ")
If rows.Length <> 0 Then
r = rows(0)
If r.Comment <> strComment Then
r.Comment = strComment
End If
End If
Catch ex As Exception
Trace.Write(ex.ToString)
End Try
End Sub
UpdateProject(ByVal Project As String, ByVal AtRiskCode As String, ByVal
Comment As String) is being called from an update button I have in the page.
The code for Update click is as follows:
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnUpdate.Click
Try
Dim strProject As String = Trim(lblProject.Text)
AtRiskProjDS.Clear()
AtRiskProjDS = LoadAtRiskProjDS(strProject)
For Each item As DataGridItem In dgAtRiskInfo.Items
If item.ItemType = ListItemType.Item Or item.ItemType =
ListItemType.AlternatingItem Then
Dim RiskCodeOld As CheckBox = CType(item.FindControl("chkCodeOld"),
CheckBox)
Dim RiskCodeNew As CheckBox = CType(item.FindControl("chkCodeNew"),
CheckBox)
Dim AtRiskCode As TextBox = CType(item.FindControl("txtAtRiskCode"),
TextBox)
Dim Description As Label = CType(item.FindControl("lblDescription"), Label)
Dim Comment As TextBox = CType(item.FindControl("txtComment"), TextBox)
Dim strAtRiskCode As String = Trim(AtRiskCode.Text)
Dim strDescription As String = Trim(Description.Text)
Dim strComment As String = Trim(Comment.Text)
If RiskCodeOld.Checked = False And RiskCodeNew.Checked = True Then
InsertProject(RiskCodeNew.Checked, strProject, strAtRiskCode,
strDescription, strComment)
RiskCodeOld.Checked = RiskCodeNew.Checked
ElseIf RiskCodeOld.Checked = True And RiskCodeNew.Checked = False Then
DeleteProject(strProject, strAtRiskCode)
RiskCodeOld.Checked = RiskCodeNew.Checked
Else
UpdateProject(strProject, strAtRiskCode, strComment)
End If
End If
Next
SubmitChanges(strProject)
Catch ex As Exception
Trace.Write(ex.ToString)
End Try
End Sub
Here is what the code for ASPX page looks like:
<%@ Import namespace="Time" %>
<%@ Import namespace="System.Data" %>
<%@ Register TagPrefix="uc1" TagName="footer" src="../footer.ascx" %>
<%@ Register TagPrefix="uc1" TagName="header" src="../header.ascx" %>
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="MaintAtRiskProjects.aspx.vb"
Inherits="Time.MaintAtRiskProjects"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>MaintAtRiskProjects</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">
<LINK href="../master.css" type="text/css" rel="stylesheet">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="MaintAtRiskProjectsFrm" method="post" runat="server">
<uc1:header id="PageHeader" runat="server"></uc1:header>
<P><asp:dropdownlist id="ddlProject" style="Z-INDEX: 101; LEFT: 16px;
POSITION: absolute; TOP: 72px"
runat="server" OnSelectedIndexChanged="DisplayAtRiskProjInfo"
Font-Names="Lucida Console, Courier New"
Width="168px" autopostback="True"></asp:dropdownlist></P>
<hr style="Z-INDEX: 102; LEFT: 8px; POSITION: absolute; TOP: 104px">
<asp:Button id="btnReport" style="Z-INDEX: 106; LEFT: 504px; POSITION:
absolute; TOP: 64px"
runat="server" Width="97px" Text="View Report"></asp:Button>
<asp:Button id="btnUpdate" style="Z-INDEX: 105; LEFT: 280px; POSITION:
absolute; TOP: 64px"
runat="server" Width="72px" Height="24px"
Text="Update"></asp:Button><asp:label id="lblProject" style="Z-INDEX: 104;
LEFT: 8px; POSITION: absolute; TOP: 128px"
runat="server" Width="160px" ForeColor="#CC0000"
Height="24px"></asp:label><asp:datagrid id="dgAtRiskInfo" style="Z-INDEX:
103; LEFT: 184px; POSITION: absolute; TOP: 128px"
runat="server" Width="385px" Height="160px" ShowFooter="False"
AutoGenerateColumns="False">
<AlternatingItemStyle BackColor="MistyRose"></AlternatingItemStyle>
<ItemStyle HorizontalAlign="Right"></ItemStyle>
<HeaderStyle ForeColor="#CC0000" BackColor="Silver"></HeaderStyle>
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:TextBox ID="txtAtRiskCode" Text='<%
#Container.DataItem("AtRiskCode") %>' Runat=server Visible=False>
</asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:CheckBox ID="chkCodeOld" Checked='<%
#Container.DataItem("RiskCodeFlag") %>' Runat="server" Visible=False>
</asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Check/Uncheck">
<ItemTemplate>
<asp:CheckBox ID="chkCodeNew" Checked='<%
#Container.DataItem("RiskCodeFlag") %>' Width="15px" Runat=server>
</asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Description">
<ItemTemplate>
<asp:Label ID="lblDescription" text='<%
#Container.DataItem("Description") %>' width="250px" runat=server>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Comment">
<ItemTemplate>
<asp:TextBox ID="txtComment" Text='<% #Container.DataItem("Comment")
%>' Width="400px" Runat=server>
</asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid></form>
</body>
</HTML>
Please help.. Can't figure out what is going on.
Thanks,
Biva
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Please help. I get the following error from my webpage:
System.InvalidCastException: Specified cast is not valid.
at Time.MaintAtRiskProjects.UpdateProject(String Project, String
AtRiskCode, String Comment)
Code for UpdateProject(String Project, String AtRiskCode, String Comment)
is:
Private Sub UpdateProject(ByVal Project As String, ByVal AtRiskCode As
String, ByVal Comment As String)
Try
Dim strProject As String = Trim(Project)
Dim strAtRiskCode As String = Trim(AtRiskCode)
Dim strComment As String = Trim(Comment)
Dim r As AtRiskProjectsDS.AtRiskProjectsRow
Dim rows() As AtRiskProjectsDS.AtRiskProjectsRow =
AtRiskProjDS.AtRiskProjects.Select(AtRiskProjDS.AtRiskProjects.ProjectColumn.ColumnName
& "= '" & strProject & "' AND " &
AtRiskProjDS.AtRiskProjects.AtRiskCodeColumn.ColumnName & "= '" &
strAtRiskCode & "' ")
If rows.Length <> 0 Then
r = rows(0)
If r.Comment <> strComment Then
r.Comment = strComment
End If
End If
Catch ex As Exception
Trace.Write(ex.ToString)
End Try
End Sub
UpdateProject(ByVal Project As String, ByVal AtRiskCode As String, ByVal
Comment As String) is being called from an update button I have in the page.
The code for Update click is as follows:
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnUpdate.Click
Try
Dim strProject As String = Trim(lblProject.Text)
AtRiskProjDS.Clear()
AtRiskProjDS = LoadAtRiskProjDS(strProject)
For Each item As DataGridItem In dgAtRiskInfo.Items
If item.ItemType = ListItemType.Item Or item.ItemType =
ListItemType.AlternatingItem Then
Dim RiskCodeOld As CheckBox = CType(item.FindControl("chkCodeOld"),
CheckBox)
Dim RiskCodeNew As CheckBox = CType(item.FindControl("chkCodeNew"),
CheckBox)
Dim AtRiskCode As TextBox = CType(item.FindControl("txtAtRiskCode"),
TextBox)
Dim Description As Label = CType(item.FindControl("lblDescription"), Label)
Dim Comment As TextBox = CType(item.FindControl("txtComment"), TextBox)
Dim strAtRiskCode As String = Trim(AtRiskCode.Text)
Dim strDescription As String = Trim(Description.Text)
Dim strComment As String = Trim(Comment.Text)
If RiskCodeOld.Checked = False And RiskCodeNew.Checked = True Then
InsertProject(RiskCodeNew.Checked, strProject, strAtRiskCode,
strDescription, strComment)
RiskCodeOld.Checked = RiskCodeNew.Checked
ElseIf RiskCodeOld.Checked = True And RiskCodeNew.Checked = False Then
DeleteProject(strProject, strAtRiskCode)
RiskCodeOld.Checked = RiskCodeNew.Checked
Else
UpdateProject(strProject, strAtRiskCode, strComment)
End If
End If
Next
SubmitChanges(strProject)
Catch ex As Exception
Trace.Write(ex.ToString)
End Try
End Sub
Here is what the code for ASPX page looks like:
<%@ Import namespace="Time" %>
<%@ Import namespace="System.Data" %>
<%@ Register TagPrefix="uc1" TagName="footer" src="../footer.ascx" %>
<%@ Register TagPrefix="uc1" TagName="header" src="../header.ascx" %>
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="MaintAtRiskProjects.aspx.vb"
Inherits="Time.MaintAtRiskProjects"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>MaintAtRiskProjects</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">
<LINK href="../master.css" type="text/css" rel="stylesheet">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="MaintAtRiskProjectsFrm" method="post" runat="server">
<uc1:header id="PageHeader" runat="server"></uc1:header>
<P><asp:dropdownlist id="ddlProject" style="Z-INDEX: 101; LEFT: 16px;
POSITION: absolute; TOP: 72px"
runat="server" OnSelectedIndexChanged="DisplayAtRiskProjInfo"
Font-Names="Lucida Console, Courier New"
Width="168px" autopostback="True"></asp:dropdownlist></P>
<hr style="Z-INDEX: 102; LEFT: 8px; POSITION: absolute; TOP: 104px">
<asp:Button id="btnReport" style="Z-INDEX: 106; LEFT: 504px; POSITION:
absolute; TOP: 64px"
runat="server" Width="97px" Text="View Report"></asp:Button>
<asp:Button id="btnUpdate" style="Z-INDEX: 105; LEFT: 280px; POSITION:
absolute; TOP: 64px"
runat="server" Width="72px" Height="24px"
Text="Update"></asp:Button><asp:label id="lblProject" style="Z-INDEX: 104;
LEFT: 8px; POSITION: absolute; TOP: 128px"
runat="server" Width="160px" ForeColor="#CC0000"
Height="24px"></asp:label><asp:datagrid id="dgAtRiskInfo" style="Z-INDEX:
103; LEFT: 184px; POSITION: absolute; TOP: 128px"
runat="server" Width="385px" Height="160px" ShowFooter="False"
AutoGenerateColumns="False">
<AlternatingItemStyle BackColor="MistyRose"></AlternatingItemStyle>
<ItemStyle HorizontalAlign="Right"></ItemStyle>
<HeaderStyle ForeColor="#CC0000" BackColor="Silver"></HeaderStyle>
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:TextBox ID="txtAtRiskCode" Text='<%
#Container.DataItem("AtRiskCode") %>' Runat=server Visible=False>
</asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:CheckBox ID="chkCodeOld" Checked='<%
#Container.DataItem("RiskCodeFlag") %>' Runat="server" Visible=False>
</asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Check/Uncheck">
<ItemTemplate>
<asp:CheckBox ID="chkCodeNew" Checked='<%
#Container.DataItem("RiskCodeFlag") %>' Width="15px" Runat=server>
</asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Description">
<ItemTemplate>
<asp:Label ID="lblDescription" text='<%
#Container.DataItem("Description") %>' width="250px" runat=server>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Comment">
<ItemTemplate>
<asp:TextBox ID="txtComment" Text='<% #Container.DataItem("Comment")
%>' Width="400px" Runat=server>
</asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid></form>
</body>
</HTML>
Please help.. Can't figure out what is going on.
Thanks,
Biva
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------