dba123
asked on
String was not recognized as a valid Boolean
I get this error when trying to run my update function. The error is happening it seems for Budget
String was not recognized as a valid Boolean.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.FormatException: String was not recognized as a valid Boolean.
Source Error:
Line 53: ds_dashboard.UpdateParamet ers("Budge t").Defaul tValue = intBudget
Line 54:
Line 55: ds_dashboard.Update()
Line 56: End If
Line 57: Next
Public Sub UpdateCustomer_DashboardGr aphs(ByVal sender As Object, ByVal e As System.EventArgs)
For Each gvr As GridViewRow In gv_dashboard.Rows
If gvr.RowType = DataControlRowType.DataRow Then
'//--IDs
Dim intCustomerID As String = CType(gvr.FindControl("lbl CustomerID "), Label).Text.Trim()
'//--Textboxes
Dim intBudget As Integer
Try
intBudget = CType(CType(gvr.FindContro l("txtBudg et"), TextBox).Text.Trim(), Int32)
Catch
intBudget = 0
End Try
'//--Checkboxes
Dim intCurrentMonthCollections As Boolean = CType(gvr.FindControl("chb x_CurrentM onthCollec tions"), CheckBox).Checked
Dim intRevenueByMonth As Boolean = CType(gvr.FindControl("chb x_RevenueB yMonth"), CheckBox).Checked
Dim intPDCsCCsMonthly As Boolean = CType(gvr.FindControl("chb x_PDCsCCsM onthly"), CheckBox).Checked
Dim intRevenueByClient As Boolean = CType(gvr.FindControl("chb x_RevenueB yClient"), CheckBox).Checked
'//--Assign UpdateParameters
If intCurrentMonthCollections = True Then
ds_dashboard.UpdateParamet ers("Curre ntMonthCol lections") .DefaultVa lue = 1
Else
ds_dashboard.UpdateParamet ers("Curre ntMonthCol lections") .DefaultVa lue = 0
End If
ds_dashboard.UpdateParamet ers("Budge t").Defaul tValue = intBudget
ds_dashboard.Update()
End If
Next
End Sub
String was not recognized as a valid Boolean.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.FormatException: String was not recognized as a valid Boolean.
Source Error:
Line 53: ds_dashboard.UpdateParamet
Line 54:
Line 55: ds_dashboard.Update()
Line 56: End If
Line 57: Next
Public Sub UpdateCustomer_DashboardGr
For Each gvr As GridViewRow In gv_dashboard.Rows
If gvr.RowType = DataControlRowType.DataRow
'//--IDs
Dim intCustomerID As String = CType(gvr.FindControl("lbl
'//--Textboxes
Dim intBudget As Integer
Try
intBudget = CType(CType(gvr.FindContro
Catch
intBudget = 0
End Try
'//--Checkboxes
Dim intCurrentMonthCollections
Dim intRevenueByMonth As Boolean = CType(gvr.FindControl("chb
Dim intPDCsCCsMonthly As Boolean = CType(gvr.FindControl("chb
Dim intRevenueByClient As Boolean = CType(gvr.FindControl("chb
'//--Assign UpdateParameters
If intCurrentMonthCollections
ds_dashboard.UpdateParamet
Else
ds_dashboard.UpdateParamet
End If
ds_dashboard.UpdateParamet
ds_dashboard.Update()
End If
Next
End Sub
what is the value of intBudget? If it's either "0" or "1", try using "True" or "False".
ASKER
no, intBudget is a textbox
This indicates to me that the definition of the UpdateParameters is incorrectly saying that the Budget field it specified to be a boolean instead of a string.
I would check that first.
Ben.
I would check that first.
Ben.
ASKER
everything about Budget is an integer. In my stored proc update command, and in my code. So why is it stating that? It may not even be the Budget field, that's just what I assume after I hit continue, since it focused on that but it may be the other UpdateParams
ASKER
Stack Trace:
String was not recognized as a valid Boolean.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.FormatException: String was not recognized as a valid Boolean.
Source Error:
Line 53: ds_dashboard.UpdateParamet ers("Budge t").Defaul tValue = intBudget
Line 54:
Line 55: ds_dashboard.Update()
Line 56: End If
Line 57: Next
Source File: Y:\inetpub\wwwroot\apex\we bapps\dash board\dash board\inde x.aspx.vb Line: 55
Stack Trace:
[FormatException: String was not recognized as a valid Boolean.]
System.Boolean.Parse(Strin g value) +2709172
System.String.System.IConv ertible.To Boolean(IF ormatProvi der provider) +12
System.Convert.ChangeType( Object value, TypeCode typeCode, IFormatProvider provider) +98
System.Web.UI.WebControls. Parameter. GetValue(O bject value, String defaultValue, TypeCode type, Boolean convertEmptyStringToNull, Boolean ignoreNullableTypeChanges) +257
System.Web.UI.WebControls. Parameter. get_Parame terValue() +91
System.Web.UI.WebControls. ParameterC ollection. GetValues( HttpContex t context, Control control) +282
System.Web.UI.WebControls. SqlDataSou rceView.In itializePa rameters(D bCommand command, ParameterCollection parameters, IDictionary exclusionList) +344
System.Web.UI.WebControls. SqlDataSou rceView.Ex ecuteUpdat e(IDiction ary keys, IDictionary values, IDictionary oldValues) +449
System.Web.UI.WebControls. SqlDataSou rceView.Up date(IDict ionary keys, IDictionary values, IDictionary oldValues) +37
System.Web.UI.WebControls. SqlDataSou rce.Update () +42
dashboard._Default.UpdateC ustomer_Da shboardGra phs(Object sender, EventArgs e) in Y:\inetpub\wwwroot\sss\web apps\dashb oard\dashb oard\index .aspx.vb:5 5
System.Web.UI.WebControls. Button.OnC lick(Event Args e) +96
System.Web.UI.WebControls. Button.Rai sePostBack Event(Stri ng eventArgument) +116
System.Web.UI.WebControls. Button.Sys tem.Web.UI .IPostBack EventHandl er.RaisePo stBackEven t(String eventArgument) +31
System.Web.UI.Page.RaisePo stBackEven t(IPostBac kEventHand ler sourceControl, String eventArgument) +32
System.Web.UI.Page.RaisePo stBackEven t(NameValu eCollectio n postData) +72
System.Web.UI.Page.Process RequestMai n(Boolean includeStagesBeforeAsyncPo int, Boolean includeStagesAfterAsyncPoi nt) +3837
String was not recognized as a valid Boolean.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.FormatException: String was not recognized as a valid Boolean.
Source Error:
Line 53: ds_dashboard.UpdateParamet
Line 54:
Line 55: ds_dashboard.Update()
Line 56: End If
Line 57: Next
Source File: Y:\inetpub\wwwroot\apex\we
Stack Trace:
[FormatException: String was not recognized as a valid Boolean.]
System.Boolean.Parse(Strin
System.String.System.IConv
System.Convert.ChangeType(
System.Web.UI.WebControls.
System.Web.UI.WebControls.
System.Web.UI.WebControls.
System.Web.UI.WebControls.
System.Web.UI.WebControls.
System.Web.UI.WebControls.
System.Web.UI.WebControls.
dashboard._Default.UpdateC
System.Web.UI.WebControls.
System.Web.UI.WebControls.
System.Web.UI.WebControls.
System.Web.UI.Page.RaisePo
System.Web.UI.Page.RaisePo
System.Web.UI.Page.Process
ASKER
Here's complete information
Why am I getting this error: String was not recognized as a valid Boolean
For Line: ds_dashboard.Update() in my update function
My SQLDataSource:
<asp:SqlDataSource
ID="ds_dashboard"
runat="server"
ConnectionString="<%$ ConnectionStrings:Dashboar dConn %>"
SelectCommand="aspx_Get_Cu stomer_Das hboardGrap hs"
SelectCommandType="StoredP rocedure"
UpdateCommand="aspx_Update _Customer_ DashboardG raphs"
UpdateCommandType="StoredP rocedure"
>
<UpdateParameters>
<asp:Parameter Name="CustomerID" Type="Int32" />
<asp:Parameter Name="Budget" Type="Int32" />
<asp:Parameter Name="CurrentMonthCollecti ons" Type="Boolean" />
<asp:Parameter Name="RevenueByMonth" Type="Boolean" />
<asp:Parameter Name="PDCsCCsMonthly" Type="Boolean" />
<asp:Parameter Name="RevenueByClient" Type="Boolean" />
</UpdateParameters>
</asp:SqlDataSource>
My GridView:
<asp:GridView
ID="gv_dashboard"
runat="server"
AutoGenerateColumns="False "
DataSourceID="ds_dashboard "
CellPadding="4"
ForeColor="#333333"
ShowFooter="True"
GridLines="None"
CssClass="FormatFont">
<Columns>
<asp:TemplateField HeaderText="Cust #" SortExpression="CustomerID ">
<HeaderStyle HorizontalAlign="center">< /HeaderSty le>
<ItemTemplate>
<asp:Label runat="server" id="lblCustomerID" Text='<%# Bind("Customer") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Budget" SortExpression="Name" ItemStyle-HorizontalAlign= "Center">
<HeaderStyle HorizontalAlign="Left"></H eaderStyle >
<ItemTemplate>
<asp:TextBox width="55px" MaxLength="10" ID="txtBudget" Text='<%# Bind("Budget") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Current Month Collections" SortExpression="Name" ItemStyle-HorizontalAlign= "Center">
<HeaderStyle HorizontalAlign="center">< /HeaderSty le>
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_CurrentMonthColle ctions" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Revenue By Month" SortExpression="Name" ItemStyle-HorizontalAlign= "Center">
<HeaderStyle HorizontalAlign="center">< /HeaderSty le>
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_RevenueByMonth" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="PDCs & CCS Monthly" SortExpression="Name" ItemStyle-HorizontalAlign= "Center">
<HeaderStyle HorizontalAlign="center">< /HeaderSty le>
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_PDCsCCsMonthly" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Revenue By Client" SortExpression="Name" ItemStyle-HorizontalAlign= "Center">
<HeaderStyle HorizontalAlign="center">< /HeaderSty le>
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_RevenueByClient" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<EditRowStyle BackColor="#DDDDDD" />
<SelectedRowStyle BackColor="#DDDDDD" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
My Update Command (Stored Procedure):
ALTER PROCEDURE [dbo].[aspx_Update_Custome r_Dashboar dGraphs]
@CustomerID bigint,
@Budget int,
@CurrentMonthCollections bit,
@RevenueByMonth bit,
@PDCsCCsMonthly bit,
@RevenueByClient bit
AS
BEGIN
UPDATE dbo.Customer_DashboardGrap hs
SET Budget = @Budget,
CurrentMonthCollections = @CurrentMonthCollections,
RevenueByMonth = @RevenueByMonth,
PDCsCCsMonthly = @PDCsCCsMonthly,
RevenueByClient = @RevenueByClient
WHERE Customer_DashboardGraphs.C ustomer = @CustomerID
END
My Table Schema:
CREATE TABLE [dbo].[Customer_DashboardG raphs](
[Customer] [nchar](10) COLLATE SQL_Latin1_General_CP1_CI_ AS NULL,
[DashboardGraphID] [bit] NULL,
[CurrentMonthCollections] [bit] NULL,
[RevenueByMonth] [bit] NULL,
[PDCsCCsMonthly] [bit] NULL,
[RevenueByClient] [bit] NULL,
[Budget] [int] NULL
) ON [PRIMARY]
Stack Trace:
String was not recognized as a valid Boolean.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.FormatException: String was not recognized as a valid Boolean.
Source Error:
Line 53: ds_dashboard.UpdateParamet ers("Budge t").Defaul tValue = intBudget
Line 54:
Line 55: ds_dashboard.Update()
Line 56: End If
Line 57: Next
Source File: Y:\inetpub\wwwroot\apex\we bapps\dash board\dash board\inde x.aspx.vb Line: 55
Stack Trace:
[FormatException: String was not recognized as a valid Boolean.]
System.Boolean.Parse(Strin g value) +2709172
System.String.System.IConv ertible.To Boolean(IF ormatProvi der provider) +12
System.Convert.ChangeType( Object value, TypeCode typeCode, IFormatProvider provider) +98
System.Web.UI.WebControls. Parameter. GetValue(O bject value, String defaultValue, TypeCode type, Boolean convertEmptyStringToNull, Boolean ignoreNullableTypeChanges) +257
System.Web.UI.WebControls. Parameter. get_Parame terValue() +91
System.Web.UI.WebControls. ParameterC ollection. GetValues( HttpContex t context, Control control) +282
System.Web.UI.WebControls. SqlDataSou rceView.In itializePa rameters(D bCommand command, ParameterCollection parameters, IDictionary exclusionList) +344
System.Web.UI.WebControls. SqlDataSou rceView.Ex ecuteUpdat e(IDiction ary keys, IDictionary values, IDictionary oldValues) +449
System.Web.UI.WebControls. SqlDataSou rceView.Up date(IDict ionary keys, IDictionary values, IDictionary oldValues) +37
System.Web.UI.WebControls. SqlDataSou rce.Update () +42
dashboard._Default.UpdateC ustomer_Da shboardGra phs(Object sender, EventArgs e) in Y:\inetpub\wwwroot\sss\web apps\dashb oard\dashb oard\index .aspx.vb:5 5
System.Web.UI.WebControls. Button.OnC lick(Event Args e) +96
System.Web.UI.WebControls. Button.Rai sePostBack Event(Stri ng eventArgument) +116
System.Web.UI.WebControls. Button.Sys tem.Web.UI .IPostBack EventHandl er.RaisePo stBackEven t(String eventArgument) +31
System.Web.UI.Page.RaisePo stBackEven t(IPostBac kEventHand ler sourceControl, String eventArgument) +32
System.Web.UI.Page.RaisePo stBackEven t(NameValu eCollectio n postData) +72
System.Web.UI.Page.Process RequestMai n(Boolean includeStagesBeforeAsyncPo int, Boolean includeStagesAfterAsyncPoi nt) +3837
Why am I getting this error: String was not recognized as a valid Boolean
For Line: ds_dashboard.Update() in my update function
My SQLDataSource:
<asp:SqlDataSource
ID="ds_dashboard"
runat="server"
ConnectionString="<%$ ConnectionStrings:Dashboar
SelectCommand="aspx_Get_Cu
SelectCommandType="StoredP
UpdateCommand="aspx_Update
UpdateCommandType="StoredP
>
<UpdateParameters>
<asp:Parameter Name="CustomerID" Type="Int32" />
<asp:Parameter Name="Budget" Type="Int32" />
<asp:Parameter Name="CurrentMonthCollecti
<asp:Parameter Name="RevenueByMonth" Type="Boolean" />
<asp:Parameter Name="PDCsCCsMonthly" Type="Boolean" />
<asp:Parameter Name="RevenueByClient" Type="Boolean" />
</UpdateParameters>
</asp:SqlDataSource>
My GridView:
<asp:GridView
ID="gv_dashboard"
runat="server"
AutoGenerateColumns="False
DataSourceID="ds_dashboard
CellPadding="4"
ForeColor="#333333"
ShowFooter="True"
GridLines="None"
CssClass="FormatFont">
<Columns>
<asp:TemplateField HeaderText="Cust #" SortExpression="CustomerID
<HeaderStyle HorizontalAlign="center"><
<ItemTemplate>
<asp:Label runat="server" id="lblCustomerID" Text='<%# Bind("Customer") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Budget" SortExpression="Name" ItemStyle-HorizontalAlign=
<HeaderStyle HorizontalAlign="Left"></H
<ItemTemplate>
<asp:TextBox width="55px" MaxLength="10" ID="txtBudget" Text='<%# Bind("Budget") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Current Month Collections" SortExpression="Name" ItemStyle-HorizontalAlign=
<HeaderStyle HorizontalAlign="center"><
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_CurrentMonthColle
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Revenue By Month" SortExpression="Name" ItemStyle-HorizontalAlign=
<HeaderStyle HorizontalAlign="center"><
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_RevenueByMonth" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="PDCs & CCS Monthly" SortExpression="Name" ItemStyle-HorizontalAlign=
<HeaderStyle HorizontalAlign="center"><
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_PDCsCCsMonthly" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Revenue By Client" SortExpression="Name" ItemStyle-HorizontalAlign=
<HeaderStyle HorizontalAlign="center"><
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_RevenueByClient" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<EditRowStyle BackColor="#DDDDDD" />
<SelectedRowStyle BackColor="#DDDDDD" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
My Update Command (Stored Procedure):
ALTER PROCEDURE [dbo].[aspx_Update_Custome
@CustomerID bigint,
@Budget int,
@CurrentMonthCollections bit,
@RevenueByMonth bit,
@PDCsCCsMonthly bit,
@RevenueByClient bit
AS
BEGIN
UPDATE dbo.Customer_DashboardGrap
SET Budget = @Budget,
CurrentMonthCollections = @CurrentMonthCollections,
RevenueByMonth = @RevenueByMonth,
PDCsCCsMonthly = @PDCsCCsMonthly,
RevenueByClient = @RevenueByClient
WHERE Customer_DashboardGraphs.C
END
My Table Schema:
CREATE TABLE [dbo].[Customer_DashboardG
[Customer] [nchar](10) COLLATE SQL_Latin1_General_CP1_CI_
[DashboardGraphID] [bit] NULL,
[CurrentMonthCollections] [bit] NULL,
[RevenueByMonth] [bit] NULL,
[PDCsCCsMonthly] [bit] NULL,
[RevenueByClient] [bit] NULL,
[Budget] [int] NULL
) ON [PRIMARY]
Stack Trace:
String was not recognized as a valid Boolean.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.FormatException: String was not recognized as a valid Boolean.
Source Error:
Line 53: ds_dashboard.UpdateParamet
Line 54:
Line 55: ds_dashboard.Update()
Line 56: End If
Line 57: Next
Source File: Y:\inetpub\wwwroot\apex\we
Stack Trace:
[FormatException: String was not recognized as a valid Boolean.]
System.Boolean.Parse(Strin
System.String.System.IConv
System.Convert.ChangeType(
System.Web.UI.WebControls.
System.Web.UI.WebControls.
System.Web.UI.WebControls.
System.Web.UI.WebControls.
System.Web.UI.WebControls.
System.Web.UI.WebControls.
System.Web.UI.WebControls.
dashboard._Default.UpdateC
System.Web.UI.WebControls.
System.Web.UI.WebControls.
System.Web.UI.WebControls.
System.Web.UI.Page.RaisePo
System.Web.UI.Page.RaisePo
System.Web.UI.Page.Process
ASKER
let's try that last paste again!
Why am I getting this error: String was not recognized as a valid Boolean
For Line: ds_dashboard.Update() in my update function
My SQLDataSource:
<asp:SqlDataSource
ID="ds_dashboard"
runat="server"
ConnectionString="<%$ ConnectionStrings:Dashboar dConn %>"
SelectCommand="aspx_Get_Cu stomer_Das hboardGrap hs"
SelectCommandType="StoredP rocedure"
UpdateCommand="aspx_Update _Customer_ DashboardG raphs"
UpdateCommandType="StoredP rocedure"
>
<UpdateParameters>
<asp:Parameter Name="CustomerID" Type="Int32" />
<asp:Parameter Name="Budget" Type="Int32" />
<asp:Parameter Name="CurrentMonthCollecti ons" Type="Boolean" />
<asp:Parameter Name="RevenueByMonth" Type="Boolean" />
<asp:Parameter Name="PDCsCCsMonthly" Type="Boolean" />
<asp:Parameter Name="RevenueByClient" Type="Boolean" />
</UpdateParameters>
</asp:SqlDataSource>
My GridView:
<asp:GridView
ID="gv_dashboard"
runat="server"
AutoGenerateColumns="False "
DataSourceID="ds_dashboard "
CellPadding="4"
ForeColor="#333333"
ShowFooter="True"
GridLines="None"
CssClass="FormatFont">
<Columns>
<asp:TemplateField HeaderText="Cust #" SortExpression="CustomerID ">
<HeaderStyle HorizontalAlign="center">< /HeaderSty le>
<ItemTemplate>
<asp:Label runat="server" id="lblCustomerID" Text='<%# Bind("Customer") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Budget" SortExpression="Name" ItemStyle-HorizontalAlign= "Center">
<HeaderStyle HorizontalAlign="Left"></H eaderStyle >
<ItemTemplate>
<asp:TextBox width="55px" MaxLength="10" ID="txtBudget" Text='<%# Bind("Budget") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Current Month Collections" SortExpression="Name" ItemStyle-HorizontalAlign= "Center">
<HeaderStyle HorizontalAlign="center">< /HeaderSty le>
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_CurrentMonthColle ctions" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Revenue By Month" SortExpression="Name" ItemStyle-HorizontalAlign= "Center">
<HeaderStyle HorizontalAlign="center">< /HeaderSty le>
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_RevenueByMonth" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="PDCs & CCS Monthly" SortExpression="Name" ItemStyle-HorizontalAlign= "Center">
<HeaderStyle HorizontalAlign="center">< /HeaderSty le>
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_PDCsCCsMonthly" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Revenue By Client" SortExpression="Name" ItemStyle-HorizontalAlign= "Center">
<HeaderStyle HorizontalAlign="center">< /HeaderSty le>
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_RevenueByClient" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<EditRowStyle BackColor="#DDDDDD" />
<SelectedRowStyle BackColor="#DDDDDD" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
My Update Command (Stored Procedure):
ALTER PROCEDURE [dbo].[aspx_Update_Custome r_Dashboar dGraphs]
@CustomerID bigint,
@Budget int,
@CurrentMonthCollections bit,
@RevenueByMonth bit,
@PDCsCCsMonthly bit,
@RevenueByClient bit
AS
BEGIN
UPDATE dbo.Customer_DashboardGrap hs
SET Budget = @Budget,
CurrentMonthCollections = @CurrentMonthCollections,
RevenueByMonth = @RevenueByMonth,
PDCsCCsMonthly = @PDCsCCsMonthly,
RevenueByClient = @RevenueByClient
WHERE Customer_DashboardGraphs.C ustomer = @CustomerID
END
My Table Schema:
CREATE TABLE [dbo].[Customer_DashboardG raphs](
[Customer] [nchar](10) COLLATE SQL_Latin1_General_CP1_CI_ AS NULL,
[DashboardGraphID] [bit] NULL,
[CurrentMonthCollections] [bit] NULL,
[RevenueByMonth] [bit] NULL,
[PDCsCCsMonthly] [bit] NULL,
[RevenueByClient] [bit] NULL,
[Budget] [int] NULL
) ON [PRIMARY]
Stack Trace:
String was not recognized as a valid Boolean.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.FormatException: String was not recognized as a valid Boolean.
Source Error:
Line 53: ds_dashboard.UpdateParamet ers("Budge t").Defaul tValue = intBudget
Line 54:
Line 55: ds_dashboard.Update()
Line 56: End If
Line 57: Next
Source File: Y:\inetpub\wwwroot\apex\we bapps\dash board\dash board\inde x.aspx.vb Line: 55
Stack Trace:
[FormatException: String was not recognized as a valid Boolean.]
System.Boolean.Parse(Strin g value) +2709172
System.String.System.IConv ertible.To Boolean(IF ormatProvi der provider) +12
System.Convert.ChangeType( Object value, TypeCode typeCode, IFormatProvider provider) +98
System.Web.UI.WebControls. Parameter. GetValue(O bject value, String defaultValue, TypeCode type, Boolean convertEmptyStringToNull, Boolean ignoreNullableTypeChanges) +257
System.Web.UI.WebControls. Parameter. get_Parame terValue() +91
System.Web.UI.WebControls. ParameterC ollection. GetValues( HttpContex t context, Control control) +282
System.Web.UI.WebControls. SqlDataSou rceView.In itializePa rameters(D bCommand command, ParameterCollection parameters, IDictionary exclusionList) +344
System.Web.UI.WebControls. SqlDataSou rceView.Ex ecuteUpdat e(IDiction ary keys, IDictionary values, IDictionary oldValues) +449
System.Web.UI.WebControls. SqlDataSou rceView.Up date(IDict ionary keys, IDictionary values, IDictionary oldValues) +37
System.Web.UI.WebControls. SqlDataSou rce.Update () +42
dashboard._Default.UpdateC ustomer_Da shboardGra phs(Object sender, EventArgs e) in Y:\inetpub\wwwroot\sss\web apps\dashb oard\dashb oard\index .aspx.vb:5 5
System.Web.UI.WebControls. Button.OnC lick(Event Args e) +96
System.Web.UI.WebControls. Button.Rai sePostBack Event(Stri ng eventArgument) +116
System.Web.UI.WebControls. Button.Sys tem.Web.UI .IPostBack EventHandl er.RaisePo stBackEven t(String eventArgument) +31
System.Web.UI.Page.RaisePo stBackEven t(IPostBac kEventHand ler sourceControl, String eventArgument) +32
System.Web.UI.Page.RaisePo stBackEven t(NameValu eCollectio n postData) +72
System.Web.UI.Page.Process RequestMai n(Boolean includeStagesBeforeAsyncPo int, Boolean includeStagesAfterAsyncPoi nt) +3837
Why am I getting this error: String was not recognized as a valid Boolean
For Line: ds_dashboard.Update() in my update function
My SQLDataSource:
<asp:SqlDataSource
ID="ds_dashboard"
runat="server"
ConnectionString="<%$ ConnectionStrings:Dashboar
SelectCommand="aspx_Get_Cu
SelectCommandType="StoredP
UpdateCommand="aspx_Update
UpdateCommandType="StoredP
>
<UpdateParameters>
<asp:Parameter Name="CustomerID" Type="Int32" />
<asp:Parameter Name="Budget" Type="Int32" />
<asp:Parameter Name="CurrentMonthCollecti
<asp:Parameter Name="RevenueByMonth" Type="Boolean" />
<asp:Parameter Name="PDCsCCsMonthly" Type="Boolean" />
<asp:Parameter Name="RevenueByClient" Type="Boolean" />
</UpdateParameters>
</asp:SqlDataSource>
My GridView:
<asp:GridView
ID="gv_dashboard"
runat="server"
AutoGenerateColumns="False
DataSourceID="ds_dashboard
CellPadding="4"
ForeColor="#333333"
ShowFooter="True"
GridLines="None"
CssClass="FormatFont">
<Columns>
<asp:TemplateField HeaderText="Cust #" SortExpression="CustomerID
<HeaderStyle HorizontalAlign="center"><
<ItemTemplate>
<asp:Label runat="server" id="lblCustomerID" Text='<%# Bind("Customer") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Budget" SortExpression="Name" ItemStyle-HorizontalAlign=
<HeaderStyle HorizontalAlign="Left"></H
<ItemTemplate>
<asp:TextBox width="55px" MaxLength="10" ID="txtBudget" Text='<%# Bind("Budget") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Current Month Collections" SortExpression="Name" ItemStyle-HorizontalAlign=
<HeaderStyle HorizontalAlign="center"><
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_CurrentMonthColle
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Revenue By Month" SortExpression="Name" ItemStyle-HorizontalAlign=
<HeaderStyle HorizontalAlign="center"><
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_RevenueByMonth" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="PDCs & CCS Monthly" SortExpression="Name" ItemStyle-HorizontalAlign=
<HeaderStyle HorizontalAlign="center"><
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_PDCsCCsMonthly" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Revenue By Client" SortExpression="Name" ItemStyle-HorizontalAlign=
<HeaderStyle HorizontalAlign="center"><
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_RevenueByClient" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<EditRowStyle BackColor="#DDDDDD" />
<SelectedRowStyle BackColor="#DDDDDD" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
My Update Command (Stored Procedure):
ALTER PROCEDURE [dbo].[aspx_Update_Custome
@CustomerID bigint,
@Budget int,
@CurrentMonthCollections bit,
@RevenueByMonth bit,
@PDCsCCsMonthly bit,
@RevenueByClient bit
AS
BEGIN
UPDATE dbo.Customer_DashboardGrap
SET Budget = @Budget,
CurrentMonthCollections = @CurrentMonthCollections,
RevenueByMonth = @RevenueByMonth,
PDCsCCsMonthly = @PDCsCCsMonthly,
RevenueByClient = @RevenueByClient
WHERE Customer_DashboardGraphs.C
END
My Table Schema:
CREATE TABLE [dbo].[Customer_DashboardG
[Customer] [nchar](10) COLLATE SQL_Latin1_General_CP1_CI_
[DashboardGraphID] [bit] NULL,
[CurrentMonthCollections] [bit] NULL,
[RevenueByMonth] [bit] NULL,
[PDCsCCsMonthly] [bit] NULL,
[RevenueByClient] [bit] NULL,
[Budget] [int] NULL
) ON [PRIMARY]
Stack Trace:
String was not recognized as a valid Boolean.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.FormatException: String was not recognized as a valid Boolean.
Source Error:
Line 53: ds_dashboard.UpdateParamet
Line 54:
Line 55: ds_dashboard.Update()
Line 56: End If
Line 57: Next
Source File: Y:\inetpub\wwwroot\apex\we
Stack Trace:
[FormatException: String was not recognized as a valid Boolean.]
System.Boolean.Parse(Strin
System.String.System.IConv
System.Convert.ChangeType(
System.Web.UI.WebControls.
System.Web.UI.WebControls.
System.Web.UI.WebControls.
System.Web.UI.WebControls.
System.Web.UI.WebControls.
System.Web.UI.WebControls.
System.Web.UI.WebControls.
dashboard._Default.UpdateC
System.Web.UI.WebControls.
System.Web.UI.WebControls.
System.Web.UI.WebControls.
System.Web.UI.Page.RaisePo
System.Web.UI.Page.RaisePo
System.Web.UI.Page.Process
ASKER
Ok, I changed these since SQL Server bit is expecting true or false, not 1 or
zero...that would be for an integer db field:
If intCurrentMonthCollections = True Then
ds_dashboard.UpdateParamet ers("Curre ntMonthCol lections") .DefaultVa lue = 1
Else
ds_dashboard.UpdateParamet ers("Curre ntMonthCol lections") .DefaultVa lue = 0
End If
to
If intCurrentMonthCollections = True Then
ds_dashboard.UpdateParamet ers("Curre ntMonthCol lections") .DefaultVa lue = True
Else
ds_dashboard.UpdateParamet ers("Curre ntMonthCol lections") .DefaultVa lue = False
End If
The error goes away but it's still not updating those bit fields in my table
zero...that would be for an integer db field:
If intCurrentMonthCollections
ds_dashboard.UpdateParamet
Else
ds_dashboard.UpdateParamet
End If
to
If intCurrentMonthCollections
ds_dashboard.UpdateParamet
Else
ds_dashboard.UpdateParamet
End If
The error goes away but it's still not updating those bit fields in my table
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ahhhhhh....hold on...
ASKER
should it also have an ID or just Checked= like you show?
ASKER
nevermind, didn't read...hold on
ASKER
An exception of type 'System.InvalidCastExcepti on' occurred in Microsoft.VisualBasic.dll but was not handled in user code
Additional information: Conversion from type 'DBNull' to type 'Boolean' is not valid.
<HeaderStyle HorizontalAlign="center">< /HeaderSty le>
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_CurrentMonthColle ctions" Checked='<%# Bind("CurrentMonthCollecti ons") %>'/>
</ItemTemplate>
</asp:TemplateField>
Additional information: Conversion from type 'DBNull' to type 'Boolean' is not valid.
<HeaderStyle HorizontalAlign="center"><
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_CurrentMonthColle
</ItemTemplate>
</asp:TemplateField>
So first off, you should not have nulls in bit fields, but in the case that you do you can always default them to false coming out of the database.
So in your query, I would change the fields that are boolean and do this:
SELECT .... ISNULL(CurrentMonthCollect ions, 0) as CurrentMonthCollections, ...
So that if it is null then it will come back 0 and then you should be good to go.
Ben.
So in your query, I would change the fields that are boolean and do this:
SELECT .... ISNULL(CurrentMonthCollect
So that if it is null then it will come back 0 and then you should be good to go.
Ben.
ASKER
How do I have nulls in there, that's what I don't get. This is a new table so there is gonna be nulls in there for the bit fields in the beginning.
ASKER
so then should I pre poplulate all values in my table for the bits field sto zero so they don't contain nulls right off the bat?
ASKER
>>So in your query, I would change the fields that are boolean and do this:
SELECT .... ISNULL(CurrentMonthCollect ions, 0) as CurrentMonthCollections, ...
so are you talking about my UpdateCommand query or SelectCommand query?
SELECT .... ISNULL(CurrentMonthCollect
so are you talking about my UpdateCommand query or SelectCommand query?
ASKER
what is ISNULL(CurrentMonthCollect ions, 0) doing?
ASKER
ok, cool. I set the ISNULL to all incoming fields in my SelectCommand Query. That got rid of the error. Now when I update my form, it doesn't produce errors but it also doesn't update the data in my table.
ASKER
Here's a recap of the code I have now...trying to figure out why with no errors, is it still not updating my table with the results:
<asp:SqlDataSource
ID="ds_dashboard"
runat="server"
ConnectionString="<%$ ConnectionStrings:Dashboar dConn %>"
SelectCommand="aspx_Get_Cu stomer_Das hboardGrap hs"
SelectCommandType="StoredP rocedure"
UpdateCommand="aspx_Update _Customer_ DashboardG raphs"
UpdateCommandType="StoredP rocedure"
>
<UpdateParameters>
<asp:Parameter Name="CustomerID" Type="Int32" />
<asp:Parameter Name="Budget" Type="Int32" />
<asp:Parameter Name="CurrentMonthCollecti ons" Type="Boolean" />
<asp:Parameter Name="RevenueByMonth" Type="Boolean" />
<asp:Parameter Name="PDCsCCsMonthly" Type="Boolean" />
<asp:Parameter Name="RevenueByClient" Type="Boolean" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:GridView
ID="gv_dashboard"
runat="server"
AutoGenerateColumns="False "
DataSourceID="ds_dashboard "
CellPadding="4"
ForeColor="#333333"
ShowFooter="True"
GridLines="None"
CssClass="FormatFont">
<Columns>
<asp:TemplateField HeaderText="Cust #" SortExpression="CustomerID ">
<HeaderStyle HorizontalAlign="center">< /HeaderSty le>
<ItemTemplate>
<asp:Label runat="server" id="lblCustomerID" Text='<%# Bind("Customer") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Budget" SortExpression="Name" ItemStyle-HorizontalAlign= "Center">
<HeaderStyle HorizontalAlign="Left"></H eaderStyle >
<ItemTemplate>
<asp:TextBox width="55px" MaxLength="10" ID="txtBudget" Text='<%# Bind("Budget") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Current Month Collections" SortExpression="Name" ItemStyle-HorizontalAlign= "Center">
<HeaderStyle HorizontalAlign="center">< /HeaderSty le>
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_CurrentMonthColle ctions" Checked='<%# Bind("CurrentMonthCollecti ons") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Revenue By Month" SortExpression="Name" ItemStyle-HorizontalAlign= "Center">
<HeaderStyle HorizontalAlign="center">< /HeaderSty le>
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_RevenueByMonth" Checked='<%# Bind("RevenueByMonth") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="PDCs & CCS Monthly" SortExpression="Name" ItemStyle-HorizontalAlign= "Center">
<HeaderStyle HorizontalAlign="center">< /HeaderSty le>
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_PDCsCCsMonthly" Checked='<%# Bind("PDCsCCsMonthly") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Revenue By Client" SortExpression="Name" ItemStyle-HorizontalAlign= "Center">
<HeaderStyle HorizontalAlign="center">< /HeaderSty le>
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_RevenueByClient" Checked='<%# Bind("RevenueByClient") %>'/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<EditRowStyle BackColor="#DDDDDD" />
<SelectedRowStyle BackColor="#DDDDDD" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
Stored proc behind the Update Command:
ALTER PROCEDURE [dbo].[aspx_Update_Custome r_Dashboar dGraphs]
@CustomerID bigint,
@Budget bigint,
@CurrentMonthCollections bit,
@RevenueByMonth bit,
@PDCsCCsMonthly bit,
@RevenueByClient bit
AS
BEGIN
UPDATE dbo.Customer_DashboardGrap hs
SET Budget = @Budget,
CurrentMonthCollections = @CurrentMonthCollections,
RevenueByMonth = @RevenueByMonth,
PDCsCCsMonthly = @PDCsCCsMonthly,
RevenueByClient = @RevenueByClient
WHERE Customer_DashboardGraphs.C ustomer = @CustomerID
END
-------------------------- ---------- - Code Behind -------------------------- ---------- ---------- ---------- -----
Public Sub UpdateCustomer_DashboardGr aphs(ByVal sender As Object, ByVal e As System.EventArgs)
For Each gvr As GridViewRow In gv_dashboard.Rows
If gvr.RowType = DataControlRowType.DataRow Then
'//--IDs
Dim intCustomerID As String = CType(gvr.FindControl("lbl CustomerID "), Label).Text.Trim()
'//--Textboxes
Dim intBudget As Integer
Try
intBudget = CType(CType(gvr.FindContro l("txtBudg et"), TextBox).Text.Trim(), Int32)
Catch
intBudget = 0
End Try
'//--Checkboxes
Dim bolCurrentMonthCollections As Boolean = CType(gvr.FindControl("chb x_CurrentM onthCollec tions"), CheckBox).Checked
Dim bolRevenueByMonth As Boolean = CType(gvr.FindControl("chb x_RevenueB yMonth"), CheckBox).Checked
Dim bolPDCsCCsMonthly As Boolean = CType(gvr.FindControl("chb x_PDCsCCsM onthly"), CheckBox).Checked
Dim bolRevenueByClient As Boolean = CType(gvr.FindControl("chb x_RevenueB yClient"), CheckBox).Checked
'//--Assign UpdateParameters
If bolCurrentMonthCollections = True Then
ds_dashboard.UpdateParamet ers("Curre ntMonthCol lections") .DefaultVa lue = True
Else
ds_dashboard.UpdateParamet ers("Curre ntMonthCol lections") .DefaultVa lue = False
End If
If bolRevenueByMonth = True Then
ds_dashboard.UpdateParamet ers("Reven ueByMonth" ).DefaultV alue = True
Else
ds_dashboard.UpdateParamet ers("Reven ueByMonth" ).DefaultV alue = False
End If
If bolPDCsCCsMonthly = True Then
ds_dashboard.UpdateParamet ers("PDCsC CsMonthly" ).DefaultV alue = True
Else
ds_dashboard.UpdateParamet ers("PDCsC CsMonthly" ).DefaultV alue = False
End If
If bolRevenueByClient = True Then
ds_dashboard.UpdateParamet ers("Reven ueByClient ").Default Value = True
Else
ds_dashboard.UpdateParamet ers("Reven ueByClient ").Default Value = False
End If
ds_dashboard.UpdateParamet ers("Budge t").Defaul tValue = intBudget
ds_dashboard.Update()
End If
Next
End Sub
<asp:SqlDataSource
ID="ds_dashboard"
runat="server"
ConnectionString="<%$ ConnectionStrings:Dashboar
SelectCommand="aspx_Get_Cu
SelectCommandType="StoredP
UpdateCommand="aspx_Update
UpdateCommandType="StoredP
>
<UpdateParameters>
<asp:Parameter Name="CustomerID" Type="Int32" />
<asp:Parameter Name="Budget" Type="Int32" />
<asp:Parameter Name="CurrentMonthCollecti
<asp:Parameter Name="RevenueByMonth" Type="Boolean" />
<asp:Parameter Name="PDCsCCsMonthly" Type="Boolean" />
<asp:Parameter Name="RevenueByClient" Type="Boolean" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:GridView
ID="gv_dashboard"
runat="server"
AutoGenerateColumns="False
DataSourceID="ds_dashboard
CellPadding="4"
ForeColor="#333333"
ShowFooter="True"
GridLines="None"
CssClass="FormatFont">
<Columns>
<asp:TemplateField HeaderText="Cust #" SortExpression="CustomerID
<HeaderStyle HorizontalAlign="center"><
<ItemTemplate>
<asp:Label runat="server" id="lblCustomerID" Text='<%# Bind("Customer") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Budget" SortExpression="Name" ItemStyle-HorizontalAlign=
<HeaderStyle HorizontalAlign="Left"></H
<ItemTemplate>
<asp:TextBox width="55px" MaxLength="10" ID="txtBudget" Text='<%# Bind("Budget") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Current Month Collections" SortExpression="Name" ItemStyle-HorizontalAlign=
<HeaderStyle HorizontalAlign="center"><
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_CurrentMonthColle
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Revenue By Month" SortExpression="Name" ItemStyle-HorizontalAlign=
<HeaderStyle HorizontalAlign="center"><
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_RevenueByMonth" Checked='<%# Bind("RevenueByMonth") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="PDCs & CCS Monthly" SortExpression="Name" ItemStyle-HorizontalAlign=
<HeaderStyle HorizontalAlign="center"><
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_PDCsCCsMonthly" Checked='<%# Bind("PDCsCCsMonthly") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Revenue By Client" SortExpression="Name" ItemStyle-HorizontalAlign=
<HeaderStyle HorizontalAlign="center"><
<ItemTemplate>
<asp:checkbox runat="server" Id="chbx_RevenueByClient" Checked='<%# Bind("RevenueByClient") %>'/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<EditRowStyle BackColor="#DDDDDD" />
<SelectedRowStyle BackColor="#DDDDDD" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
Stored proc behind the Update Command:
ALTER PROCEDURE [dbo].[aspx_Update_Custome
@CustomerID bigint,
@Budget bigint,
@CurrentMonthCollections bit,
@RevenueByMonth bit,
@PDCsCCsMonthly bit,
@RevenueByClient bit
AS
BEGIN
UPDATE dbo.Customer_DashboardGrap
SET Budget = @Budget,
CurrentMonthCollections = @CurrentMonthCollections,
RevenueByMonth = @RevenueByMonth,
PDCsCCsMonthly = @PDCsCCsMonthly,
RevenueByClient = @RevenueByClient
WHERE Customer_DashboardGraphs.C
END
--------------------------
Public Sub UpdateCustomer_DashboardGr
For Each gvr As GridViewRow In gv_dashboard.Rows
If gvr.RowType = DataControlRowType.DataRow
'//--IDs
Dim intCustomerID As String = CType(gvr.FindControl("lbl
'//--Textboxes
Dim intBudget As Integer
Try
intBudget = CType(CType(gvr.FindContro
Catch
intBudget = 0
End Try
'//--Checkboxes
Dim bolCurrentMonthCollections
Dim bolRevenueByMonth As Boolean = CType(gvr.FindControl("chb
Dim bolPDCsCCsMonthly As Boolean = CType(gvr.FindControl("chb
Dim bolRevenueByClient As Boolean = CType(gvr.FindControl("chb
'//--Assign UpdateParameters
If bolCurrentMonthCollections
ds_dashboard.UpdateParamet
Else
ds_dashboard.UpdateParamet
End If
If bolRevenueByMonth = True Then
ds_dashboard.UpdateParamet
Else
ds_dashboard.UpdateParamet
End If
If bolPDCsCCsMonthly = True Then
ds_dashboard.UpdateParamet
Else
ds_dashboard.UpdateParamet
End If
If bolRevenueByClient = True Then
ds_dashboard.UpdateParamet
Else
ds_dashboard.UpdateParamet
End If
ds_dashboard.UpdateParamet
ds_dashboard.Update()
End If
Next
End Sub
It says in the SelectCommand to make the return a 0 if the field value in the database table is a NULL. When the error was thrown and it said that you cannot set the value of a Checked field to DBNull, that meant that it encountered a NULL in the data coming back.
So in aspx_Get_Customer_Dashboar dGraphs you could go in and change the CurrentMonthCollections to ISNULL(CurrentMonthCollect ions, 0) as CurrentMonthCollections and so forth for all bit fields.
The other way to do it is to use the function in the code to do it.
Change to
<asp:checkbox runat="server" Id="chbx_CurrentMonthColle ctions" Checked='<%# GetBooleanValue(Bind("Curr entMonthCo llections" )) %>'/>
Then in your code
Private Function GetBooleanValue(boolValue as object) as Boolean
If boolValue = DBNull.Value Then
Return False
Else
Return CType(boolValue, Boolean)
End If
End Function
If you add the code and do the above, then you would NOT change the stored procedure, you would just leave it as is. I am not sure that the Bind() works inside a function call, but if it does not then you will want to put it as Eval( ) instead of Bind( ).
Ben.
So in aspx_Get_Customer_Dashboar
The other way to do it is to use the function in the code to do it.
Change to
<asp:checkbox runat="server" Id="chbx_CurrentMonthColle
Then in your code
Private Function GetBooleanValue(boolValue as object) as Boolean
If boolValue = DBNull.Value Then
Return False
Else
Return CType(boolValue, Boolean)
End If
End Function
If you add the code and do the above, then you would NOT change the stored procedure, you would just leave it as is. I am not sure that the Bind() works inside a function call, but if it does not then you will want to put it as Eval( ) instead of Bind( ).
Ben.
ASKER
a few questions to try and troubleshoot this more.
example, should this be type Boolean? I assume yes but not sure exactly what value is returned (true, false, "true", or "false") by VB.NET
Dim bolRevenueByClient As Boolean = CType(gvr.FindControl("chb x_RevenueB yClient"), CheckBox).Checked
should this be set to "true" or "false", or true or false, or 1 or 0. I know that 1 or 0 causes issues
ds_dashboard.UpdateParamet ers("Curre ntMonthCol lections") .DefaultVa lue = True
Else
ds_dashboard.UpdateParamet ers("Curre ntMonthCol lections") .DefaultVa lue = False
End If
how and what is being passed to my SQL DB table which has type bit for these fields?
example, should this be type Boolean? I assume yes but not sure exactly what value is returned (true, false, "true", or "false") by VB.NET
Dim bolRevenueByClient As Boolean = CType(gvr.FindControl("chb
should this be set to "true" or "false", or true or false, or 1 or 0. I know that 1 or 0 causes issues
ds_dashboard.UpdateParamet
Else
ds_dashboard.UpdateParamet
End If
how and what is being passed to my SQL DB table which has type bit for these fields?
So when you do a .Checked it returns True or False.
Same when you try to set the .Checked to something. All that will work is True and False and they are in fact Boolean.
When you bring things from SQL Server into VB.NET it will change the 0 or 1 that is actually stored in the table (because 0 or 1 are the only possible values for a bit field) and change it to a True or False, not "true" or "false". So when putting things back, the UpdateParameters wants a Boolean (True or False) instead of a 1 or a 0 or a string and it will put it in correctly to the table as a 0 or a 1.
So the easiest way is to use the function to detect the DBNull.Value and otherwise return what is in the table.
Make sense?
Ben.
Same when you try to set the .Checked to something. All that will work is True and False and they are in fact Boolean.
When you bring things from SQL Server into VB.NET it will change the 0 or 1 that is actually stored in the table (because 0 or 1 are the only possible values for a bit field) and change it to a True or False, not "true" or "false". So when putting things back, the UpdateParameters wants a Boolean (True or False) instead of a 1 or a 0 or a string and it will put it in correctly to the table as a 0 or a 1.
So the easiest way is to use the function to detect the DBNull.Value and otherwise return what is in the table.
Make sense?
Ben.
ASKER
so in other words I should be doing:
ds_dashboard.UpdateParamet ers("Curre ntMonthCol lections") .DefaultVa lue = 1
Else
ds_dashboard.UpdateParamet ers("Curre ntMonthCol lections") .DefaultVa lue = 0
End If
but that throws errors...saying it's not the right type for boolean
ds_dashboard.UpdateParamet
Else
ds_dashboard.UpdateParamet
End If
but that throws errors...saying it's not the right type for boolean
ASKER
Also, If I open my table in SQL Management Studio in SQL 2005 and type in 1 for one of the bit fields, it tells me this:
Invalid Value for Cell
The changed value in this cell was not recognized as valid
.Net Framework Data Type: Boolean
Error Message: String was not recognized as a valid Boolean
ahh, so this explains it. But you were saying that it can only hold a 1 or 0. I agree with you as I have worked with bit in the past. But the only thing I can type in the DB directly, or update it with is the text True or False.
Invalid Value for Cell
The changed value in this cell was not recognized as valid
.Net Framework Data Type: Boolean
Error Message: String was not recognized as a valid Boolean
ahh, so this explains it. But you were saying that it can only hold a 1 or 0. I agree with you as I have worked with bit in the past. But the only thing I can type in the DB directly, or update it with is the text True or False.
ASKER
so this should be right:
ds_dashboard.UpdateParamet ers("Curre ntMonthCol lections") .DefaultVa lue = True
Else
ds_dashboard.UpdateParamet ers("Curre ntMonthCol lections") .DefaultVa lue = False
It looks like SQL Server bit type doesn't hold 1 or 0 litrally now, it holds True or False.
End If
ds_dashboard.UpdateParamet
Else
ds_dashboard.UpdateParamet
It looks like SQL Server bit type doesn't hold 1 or 0 litrally now, it holds True or False.
End If
ASKER
so getting back to the root of my problem now...being that my latest post is not updating my table....that long post that shows you my latest code. Why is nothing being updated if no errors are occuring? Is it something with my update statement in the UpdateCommand or what I'm passing to it ? (True or False) ? The budget txt field isn't even updating either.
OK, but where is your CustomerId parameter?
You have
Dim intCustomerID As String = CType(gvr.FindControl("lbl CustomerID "), Label).Text.Trim()
But nowhere do I see you setting that Parameter up.
ds_dashboard.UpdateParamet ers("Custo merID").De faultValue = intCustomerID
That would be one reason why the update is not happening.
Ben.
You have
Dim intCustomerID As String = CType(gvr.FindControl("lbl
But nowhere do I see you setting that Parameter up.
ds_dashboard.UpdateParamet
That would be one reason why the update is not happening.
Ben.
ASKER
Thanks for that, that was it, missing the customer ID.
Wow, all that and we missed the CustomerID Parameter.