Showing posts with label workaround. Show all posts
Showing posts with label workaround. Show all posts

Tuesday, March 27, 2012

Boolean Data Type not available (workaround for checkbox.checked storing?)

I have a page for inventory price entry that I have used for a while. Now I need to add a checkbox for whether or not the price includes shipping. I added the checkbox to the form and had it posting 'True' or 'False' to the database as nchar(10) data type. When the gridview pulls up the data, I have the Item Template like this, so it shows a disabled checkbox either checked or not:

<asp:CheckBoxID="CheckBox2"runat="server"Checked='<%# Convert.ToBoolean(Eval("Shipping")) %>'Enabled="False"/>

This works fine for displaying the values, but I copied the checkbox to the Edit Item Template, but did not disabled this one. At first, I didn't change the databindings, leaving it Convert.ToBoolean(Eval("Shipping")), which allowed me to go into Edit mode, change the checkbox, then click update. At which point it would return to it's original state (meaning Update wasn't actually updating). However if I change the databindings, then the page won't display.

I checked the SQL statement, and sure enough, it has the

UpdateCommand="UPDATE [PartsTable] ... SET [Shipping] = @.Shipping... WHERE [PartID] = @.original_PartID

After fiddling with the sql statement, now I get Object cannot be cast from DBNull to other types. I think that means that the checkbox is sending a null value to the database.

Any insight as to how to get this to work is much appreciated. Thanks in advance.

I don't know if this will work declaratively but your problem is ANSI SQL Boolean is three valued True/False/Null the reason ANSI SQL is called three valued logic. The links below will show how to use Nullable types of FCL(framework class library) 2.0 to solve your problem. Hope this helps.

http://www.codeproject.com/csharp/c__20_nullable_types.asp

http://www.c-sharpcorner.com/UploadFile/PashuSX/NullableTypes04282006114548AM/NullableTypes.aspx?ArticleID=b28a5114-a92a-4ced-a23c-06d8a29de6e4

|||

I found this thread:http://forums.asp.net/thread/1092916.aspx and after reading it, I've changed the data type in the database to Bit. This has significantly helped my problem .

BUT I have the checkbox in normal mode displaying perfectly fine. However, when I click edit, there is a textbox that displays either True or False (True is 1 and False is 0 in the database). If I change True to 0 or False to 1, it works. HOWEVER I want it to display a textbox. When I delete the textbox in the edit template, replace it with a checkbox and then set the databinding to the shipping field, I can click edit and the box appears just fine, but when I change it and click update, I get this Error:Syntax error converting the nvarchar value 'False' to a column of data type bit.Which to me means that it is trying to post the checkbox.checked ='s value, not just checkbox.checked which is stored as a bit in the database.

How/Where can I change this?

|||Figured it out! Turns out the auto generated update statement set the paramenter to

<asp:ParameterName="Shipping"Type="String"/>

So I took out the Type="String" and it fixed my problem.

Thanks.

|||I am glad to see your problem is resolved.

Thursday, February 16, 2012

Blank hostname in profiler, anyone got a workaround?

Doing a profile on a server, I'm getting blank hostnames coming through. I
think we've found that they're coming from some legacy ColdFusion code.
However, when I profile and set a filter of a specific hostname, I still get
line entries that have empty hostnames.
The only item in the MS Support site talks about system processes, which
these are not.
Anyone know of a way to filter out these entries that I do not want to see?Technically, they are NULL, not blank. The Profiler GUI presents them as
blanks. Unfortunately, NULL matches any filter condition, so NULL fields
get through. You can dump the Profiler output to a SQL table and do some
querying on it to improve your filtering capabilities.
--
Geoff N. Hiten
Microsoft SQL Server MVP
Senior Database Administrator
Careerbuilder.com
I support the Professional Association for SQL Server
www.sqlpass.org
"Patrick Parker" <pparker@.motivaction.com> wrote in message
news:uGysrkq5DHA.1504@.TK2MSFTNGP12.phx.gbl...
> Doing a profile on a server, I'm getting blank hostnames coming through.
I
> think we've found that they're coming from some legacy ColdFusion code.
> However, when I profile and set a filter of a specific hostname, I still
get
> line entries that have empty hostnames.
> The only item in the MS Support site talks about system processes, which
> these are not.
> Anyone know of a way to filter out these entries that I do not want to
see?
>
>

Blank hostname in profiler, anyone got a workaround?

Doing a profile on a server, I'm getting blank hostnames coming through. I
think we've found that they're coming from some legacy ColdFusion code.
However, when I profile and set a filter of a specific hostname, I still get
line entries that have empty hostnames.
The only item in the MS Support site talks about system processes, which
these are not.
Anyone know of a way to filter out these entries that I do not want to see?Technically, they are NULL, not blank. The Profiler GUI presents them as
blanks. Unfortunately, NULL matches any filter condition, so NULL fields
get through. You can dump the Profiler output to a SQL table and do some
querying on it to improve your filtering capabilities.
Geoff N. Hiten
Microsoft SQL Server MVP
Senior Database Administrator
Careerbuilder.com
I support the Professional Association for SQL Server
www.sqlpass.org
"Patrick Parker" <pparker@.motivaction.com> wrote in message
news:uGysrkq5DHA.1504@.TK2MSFTNGP12.phx.gbl...
quote:

> Doing a profile on a server, I'm getting blank hostnames coming through.

I
quote:

> think we've found that they're coming from some legacy ColdFusion code.
> However, when I profile and set a filter of a specific hostname, I still

get
quote:

> line entries that have empty hostnames.
> The only item in the MS Support site talks about system processes, which
> these are not.
> Anyone know of a way to filter out these entries that I do not want to

see?
quote:

>
>