Saturday, March 31, 2012

String String Function

All the String functions like 'Len', 'Left', 'Right', 'Mid' etc. that
are available in ASP are supported by ASP.NET as well except for the
string function 'String'.

The 'String' function takes this form:

String(number, character)

which returns a string consisting of *character* which is repeated
*number* times. For e.g.

String(3, "$")

would return

$$$

or

String(5, "A")

would return

AAAAA

But when I try to use this function in ASP.NET, the following error
gets generated

'String' is a class type and cannot be used as an expression.

It's pretty obvious what makes ASP.NET generate the above error but
how do I make use of this 'String' function in ASP.NET? Is there any
equivalent string function in ASP.NET?

Actually my main intention is to replace the first 10 characters of a
text with dots irrespective of the no. of characters in the text (or
the 'Len' of the text) which is why I needed to use the 'String'
function. Had ASP.NET supported the 'String' function, then the
following would have served my purpose:

strText = "The quick brown fox jumps over the lazy dog."
strText = String(10, ".") & Mid(strText, 11, Len(strText))

I can't use the 'Replace' function since the first 10 characters (or,
for that matter, the entire text) can be a combination any characters
(even non-alphanumeric).string str = new string(' ', 10);

<rn5a@dotnet.itags.org.rediffmail.comwrote in message
news:1170864460.723705.243170@dotnet.itags.org.k78g2000cwa.googlegr oups.com...

Quote:

Originally Posted by

All the String functions like 'Len', 'Left', 'Right', 'Mid' etc. that
are available in ASP are supported by ASP.NET as well except for the
string function 'String'.
>
The 'String' function takes this form:
>
String(number, character)
>
which returns a string consisting of *character* which is repeated
*number* times. For e.g.
>
String(3, "$")
>
would return
>
$$$
>
or
>
String(5, "A")
>
would return
>
AAAAA
>
But when I try to use this function in ASP.NET, the following error
gets generated
>
'String' is a class type and cannot be used as an expression.
>
It's pretty obvious what makes ASP.NET generate the above error but
how do I make use of this 'String' function in ASP.NET? Is there any
equivalent string function in ASP.NET?
>
Actually my main intention is to replace the first 10 characters of a
text with dots irrespective of the no. of characters in the text (or
the 'Len' of the text) which is why I needed to use the 'String'
function. Had ASP.NET supported the 'String' function, then the
following would have served my purpose:
>
strText = "The quick brown fox jumps over the lazy dog."
strText = String(10, ".") & Mid(strText, 11, Len(strText))
>
I can't use the 'Replace' function since the first 10 characters (or,
for that matter, the entire text) can be a combination any characters
(even non-alphanumeric).
>


On Feb 7, 9:17 pm, "Aidy" <a...@dotnet.itags.org.noemail.xxxa.comwrote:

Quote:

Originally Posted by

string str = new string(' ', 10);
>
<r...@dotnet.itags.org.rediffmail.comwrote in message
>
news:1170864460.723705.243170@dotnet.itags.org.k78g2000cwa.googlegr oups.com...
>
>
>

Quote:

Originally Posted by

All the String functions like 'Len', 'Left', 'Right', 'Mid' etc. that
are available in ASP are supported by ASP.NET as well except for the
string function 'String'.


>

Quote:

Originally Posted by

The 'String' function takes this form:


>

Quote:

Originally Posted by

String(number, character)


>

Quote:

Originally Posted by

which returns a string consisting of *character* which is repeated
*number* times. For e.g.


>

Quote:

Originally Posted by

String(3, "$")


>

Quote:

Originally Posted by

would return


>

Quote:

Originally Posted by

$$$


>

Quote:

Originally Posted by

or


>

Quote:

Originally Posted by

String(5, "A")


>

Quote:

Originally Posted by

would return


>

Quote:

Originally Posted by

AAAAA


>

Quote:

Originally Posted by

But when I try to use this function in ASP.NET, the following error
gets generated


>

Quote:

Originally Posted by

'String' is a class type and cannot be used as an expression.


>

Quote:

Originally Posted by

It's pretty obvious what makes ASP.NET generate the above error but
how do I make use of this 'String' function in ASP.NET? Is there any
equivalent string function in ASP.NET?


>

Quote:

Originally Posted by

Actually my main intention is to replace the first 10 characters of a
text with dots irrespective of the no. of characters in the text (or
the 'Len' of the text) which is why I needed to use the 'String'
function. Had ASP.NET supported the 'String' function, then the
following would have served my purpose:


>

Quote:

Originally Posted by

strText = "The quick brown fox jumps over the lazy dog."
strText = String(10, ".") & Mid(strText, 11, Len(strText))


>

Quote:

Originally Posted by

I can't use the 'Replace' function since the first 10 characters (or,
for that matter, the entire text) can be a combination any characters
(even non-alphanumeric).- Hide quoted text -


>
- Show quoted text -


Thanks a lot, Aidy :-)

String String Function

All the String functions like 'Len', 'Left', 'Right', 'Mid' etc. that
are available in ASP are supported by ASP.NET as well except for the
string function 'String'.
The 'String' function takes this form:
String(number, character)
which returns a string consisting of *character* which is repeated
*number* times. For e.g.
String(3, "$")
would return
$$$
or
String(5, "A")
would return
AAAAA
But when I try to use this function in ASP.NET, the following error
gets generated
'String' is a class type and cannot be used as an expression.
It's pretty obvious what makes ASP.NET generate the above error but
how do I make use of this 'String' function in ASP.NET? Is there any
equivalent string function in ASP.NET?
Actually my main intention is to replace the first 10 characters of a
text with dots irrespective of the no. of characters in the text (or
the 'Len' of the text) which is why I needed to use the 'String'
function. Had ASP.NET supported the 'String' function, then the
following would have served my purpose:
strText = "The quick brown fox jumps over the lazy dog."
strText = String(10, ".") & Mid(strText, 11, Len(strText))
I can't use the 'Replace' function since the first 10 characters (or,
for that matter, the entire text) can be a combination any characters
(even non-alphanumeric).string str = new string(' ', 10);
<rn5a@.rediffmail.com> wrote in message
news:1170864460.723705.243170@.k78g2000cwa.googlegroups.com...
> All the String functions like 'Len', 'Left', 'Right', 'Mid' etc. that
> are available in ASP are supported by ASP.NET as well except for the
> string function 'String'.
> The 'String' function takes this form:
> String(number, character)
> which returns a string consisting of *character* which is repeated
> *number* times. For e.g.
> String(3, "$")
> would return
> $$$
> or
> String(5, "A")
> would return
> AAAAA
> But when I try to use this function in ASP.NET, the following error
> gets generated
> 'String' is a class type and cannot be used as an expression.
> It's pretty obvious what makes ASP.NET generate the above error but
> how do I make use of this 'String' function in ASP.NET? Is there any
> equivalent string function in ASP.NET?
> Actually my main intention is to replace the first 10 characters of a
> text with dots irrespective of the no. of characters in the text (or
> the 'Len' of the text) which is why I needed to use the 'String'
> function. Had ASP.NET supported the 'String' function, then the
> following would have served my purpose:
> strText = "The quick brown fox jumps over the lazy dog."
> strText = String(10, ".") & Mid(strText, 11, Len(strText))
> I can't use the 'Replace' function since the first 10 characters (or,
> for that matter, the entire text) can be a combination any characters
> (even non-alphanumeric).
>
On Feb 7, 9:17 pm, "Aidy" <a...@.noemail.xxxa.com> wrote:
> string str = new string(' ', 10);
> <r...@.rediffmail.com> wrote in message
> news:1170864460.723705.243170@.k78g2000cwa.googlegroups.com...
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> - Show quoted text -
Thanks a lot, Aidy :-)

String Stripping

Hi,

I am trying to create a page that will check user input against a value in database. This page will have a text box for user to enter serial #.
Serial # length is variable but last 3 digit is always number.
For examples:
W04051234-PAY001 in this example code is 1234-PAY
W05051234-PAT002 in this example code is 1234-PAT

A12056040-G001 in this example code is 6040-G
B11056080-SU001 in this example code is 6080-s

Which is the best approach to extract CODE from user input?

Any help will be appriciated.

Thank

TekinUse the Regular Expression class, RegExp with a regular expression that looks for:
4 digits (or is it 3?) followed by
dash
followed by 1 or letters

That expression is:
\d{4}\-[A-Za-z]+
Actually,

I would like to Trancate first 5 digits and last 3 digits.

For examples:
W04051234-PAY001 in this example code is 1234-PAY
If you are attempting to strip a specific group of characters, the String class has numerous useful methods. I encourage you to read about the String class in the .net docs. I think the SubString() and Length() methods will be useful.

String to a Class name

Hi,

I've got some classes to access different types of databases and I have a string variable that define the type of db I want to access. What I want to do if is pssible use the value of this variable to access the class. I have the following code now.


switch (dbType)
{
case "MSSQL": return MSSQL.msSQLDataSet(sqlString);
case "ACCESS": return ACCESS.msSQLDataSet(sqlString);
case "ORACLE": return ORACLE.msSQLDataSet(sqlString);
case "MYSQL": return MYSQL.msSQLDataSet(sqlString);

default: return null;
}

I want to do something like


SomekindOfTransformation(dbType).msSQLDataSet(sqlString)

instead of using theswitch statement

Thanks,Hi Arty,

You can achieve it using Object.GetType and Type.InvokeMember. VisitObject.GetType andType.InvokeMember for complete details.

Here is a sample code:

using System;
using System.Reflection;

// This sample class has a field, constructor, method, and property.
class MyType
{
Int32 myField;
public MyType(ref Int32 x) {x *= 5;}
public override String ToString() {return myField.ToString();}
public Int32 MyProp
{
get {return myField;}
set
{
if (value < 1)
throw new ArgumentOutOfRangeException("value", value, "value must be > 0");
myField = value;
}
}
}

class MyApp
{
static void Main()
{
Type t = typeof(MyType);
// Create an instance of a type.
Object[] args = new Object[] {8};
Console.WriteLine("The value of x before the constructor is called is {0}.", args[0]);
Object obj = t.InvokeMember(null,
BindingFlags.DeclaredOnly |
BindingFlags.Public | BindingFlags.NonPublic |
BindingFlags.Instance | BindingFlags.CreateInstance, null, null, args);
Console.WriteLine("Type: " + obj.GetType().ToString());
Console.WriteLine("The value of x after the constructor returns is {0}.", args[0]);

// Read and write to a field.
t.InvokeMember("myField",
BindingFlags.DeclaredOnly |
BindingFlags.Public | BindingFlags.NonPublic |
BindingFlags.Instance | BindingFlags.SetField, null, obj, new Object[] {5});
Int32 v = (Int32) t.InvokeMember("myField",
BindingFlags.DeclaredOnly |
BindingFlags.Public | BindingFlags.NonPublic |
BindingFlags.Instance | BindingFlags.GetField, null, obj, null);
Console.WriteLine("myField: " + v);

// Call a method.
String s = (String) t.InvokeMember("ToString",
BindingFlags.DeclaredOnly |
BindingFlags.Public | BindingFlags.NonPublic |
BindingFlags.Instance | BindingFlags.InvokeMethod, null, obj, null);
Console.WriteLine("ToString: " + s);

// Read and write a property. First, attempt to assign an
// invalid value; then assign a valid value; finally, get
// the value.
try
{
// Assign the value zero to MyProp. The Property Set
// throws an exception, because zero is an invalid value.
// InvokeMember catches the exception, and throws
// TargetInvocationException. To discover the real cause
// you must catch TargetInvocationException and examine
// the inner exception.
t.InvokeMember("MyProp",
BindingFlags.DeclaredOnly |
BindingFlags.Public | BindingFlags.NonPublic |
BindingFlags.Instance | BindingFlags.SetProperty, null, obj, new Object[] {0});
}
catch (TargetInvocationException e)
{
// If the property assignment failed for some unexpected
// reason, rethrow the TargetInvocationException.
if (e.InnerException.GetType() !=
typeof(ArgumentOutOfRangeException))
throw;
Console.WriteLine("An invalid value was assigned to MyProp.");
}
t.InvokeMember("MyProp",
BindingFlags.DeclaredOnly |
BindingFlags.Public | BindingFlags.NonPublic |
BindingFlags.Instance | BindingFlags.SetProperty, null, obj, new Object[] {2});
v = (Int32) t.InvokeMember("MyProp",
BindingFlags.DeclaredOnly |
BindingFlags.Public | BindingFlags.NonPublic |
BindingFlags.Instance | BindingFlags.GetProperty, null, obj, null);
Console.WriteLine("MyProp: " + v);
}
}

Hope this helps,
Appan
Thank you Appana, that helped me a lot.

String to Base64

Hi,

I need to convert an ASCII string to Base64 encoding in VB .NET. All of the references I have found show how to convert a binary data stream to Base64, but I only need to convert a text string. What is the simplest way to do this?

Hi,

It is always advisable to convert to binary first before performing encoding or encrypting operations. You can convert the string to binary and then encode to Base64.

Hope this helps,

Vivek

string to byte array conversion

I've a string similiar to "A509DE5B" (Length == 8 ) where each 2 characters are 1 hex number. How to convert such string into array of bytes (Lenght == 4)? In C# please, it's important...Byte.Parse()?

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystembyteclassparsetopic.asp
Hi LesioS!

I think you should try out something like this (I haven't tested it out myself, not sure if it works!!)


string sBytes = "A509DE5B";

Byte[] bytes = new Byte[(int)(sBytes.Length/2)];

int i = 0, j = 0;

while(i < sBytes.Length)
{
bytes[j] = Byte.Parse(str.Substring(i,2), NumberStyles.HexNumber);
i += 2;
}

Maybe it would work..

Good luck!
Oh, sorry, there's lots of mistakes in the code earlier code.

I tested this, and it worked, so be my guest! :)


string sBytes = "A509DE5B";
int i=0, j=0;
Byte[] bytes = new Byte[(int)(sBytes.Length/2)];
while(i < str.Length)
{
bytes[j] = Byte.Parse(sBytes.Substring(i,2), NumberStyles.HexNumber);
i += 2;
}


byte[] bytes = new byte[str.Length / 2];
for(int i = 0; i < str.Length / 2; i++)
bytes [i] = Byte.Parse(str.Substring(i * 2, 2), NumberStyles.HexNumber);

works fine... THX

But I wonder why there's no such function like ToCharArray for string object which produces byte array. In many cases functions from .NET Framework uses byte arrays, not char arrays :(

Try this:

// C# to convert a string to a byte array.
public static byte[] StrToByteArray(string str)
{
System.Text.ASCIIEncoding encoding=new System.Text.ASCIIEncoding();
return encoding.GetBytes(str);
}

Good luck!

Newbie


I have tried this

System.Text.

ASCIIEncoding encoding =new System.Text.ASCIIEncoding();string queryStringKey =ConfigurationManager.AppSettings["queryStringKey"];byte[] key = encoding.GetBytes(queryStringKey);return key;

to achieve this

//byte[] Key = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6 };

but it is not working. What am I not getting? Newbie

String to convert into Double

Hello All,

I am having string object coming from a DataSet. It can contain either the Numeric Strings (like "123","123.23",...) or even the Character string (Like "America","Britain"...).

Now, I am assigning this value to another column in the dataset whose datatype is Doube. Now, I wanted to check before assigning whether whatever the String I am getting from the Source column can it be converted to Double or not?

i.e I want to know is there any object/method in .Net Framework using which I can know whether I can convert one datatype to another datatype or not?

Any help regarding this would be great.

Thanks in Advance,
Areef.Hi Areef,
I am not familiar with such an object, but you can use Double.TryParse to perform your task.
Hi pmd_areef,

Try the following for testing if value is a Double. Example:


[C#]
/// <summary>
/// Is the value supplied numeric (Integer, Double).
/// </summary>
/// <param name="number">Value to test</param>
/// <returns></returns>
public bool IsNumeric(object number)
{
double tempResult;
return IsNumeric(number, out tempResult);
}

public bool IsNumeric(object number, out double result)
{
return Double.TryParse(number.ToString(), System.Globalization.NumberStyles.Any,
System.Globalization.NumberFormatInfo.InvariantInfo, out result);
}


Hope this helps.

String to Control.ClientId

Hi.
Is there a way I can convert a string (let's say it's"vw501") sent by a querystring, to a Control's ClientID, like myMultiView.SetActiceView(vw501) ?

I've tried this, which fails:
Dim vName As String = TRim(Request.Querystring("vName"))
myMultiView.SetActiveView(vName)

Regards,

Roy

The FindControl method might help you there. Seehttp://msdn2.microsoft.com/de-de/library/system.web.ui.control.findcontrol.aspx

Make sure you use the FindControl method on the Control your views are nested in. Say if your Views are inside a Form named form1, like so:

myMultiView.SetActiveView( form1.FindControl(vName) )


Thanks a lot :-)
It works!

Roy

string to control name

I am looking for the way to convert a string, say it's called sTemp, to the actual control name.
I have say cMyControl as Control.
I want to set cMyControl = sTemp
I can't seem to find the right way to convert the string.

Thanks all,

ZathHi Zath,
You are trying to equal a string to a type Control. Which does not make sense. Its like equalling a line of text to your monitor. A Control has so many properties, like control ID, child controls, Parent and blah blah. So now, what you are trying to achieve and why
Thanks for the reply.

I have 4 imagas on a page. Depending on the number in the db field, I want the number of images to be visible.


'For i = 1 To intCnt 'intCnt is the number in the field
' sTmp = ("imgTest" & i) 'For the image names - imgTest1, imgTest2......
' j = CType(sTmp, Control) ' This line doesn't work
' j.Visible = True
'Next

Now it can be done with some if then statements, but if I ever increase the number above 4 in the db, then I will have to adjust the code.
And all the images are the same.
If there is a better way to do this, any suggestions are appreciated.

Zath

For i = 1 To intCnt
j = FindControl("imgTest" + i.ToString())

If Not j Is Nothing Then
j.Visible = True
End If
Next


Cool, thanks! Worked great.

Should have thought of that. I use the findcontrol for datagrid templates all the time....

Zath

String to date

I have a string which contains a date in "MM/dd/yyyy" format. How to I convert that in VB to "dd/MM/yyyy"

Please see this post.

http://forums.asp.net/1167602/ShowPost.aspx


Thanks for that

String To Date

Hi, I have a vb.net/asp.net 1.1 web application that may be used in
other cultures where dates are formatted differently. I have three
controls (either DropDowns or TextBoxes) one for year, one for month,
and one for day.
I'd like to be able to convert this to a DateTime type of variable and
not have to rely on or find the localization settings.
My idea was to populate the DateTime.Year, DateTime.Month and
DateTime.Day from the controls, (like Date.Year = txtYear.Text) but
those properties are read-only.
I know I could make a string like "12-19-2005" and do a
strDate.ToDateTime but that will break as soon as the application is
used where dd-mm-yyyy is the norm.
So If I have three variables representing year, month, and day what's
the best way to convert to Date without relying on any kind of
localization setting? Thanks!
Mattit works in ASPNET 2.0,
it should work in ASP.NET1.x
Dim MyDate As New DateTime(2005, 12, 19)
Daniel TIZON
MCP - MCSD.NET - MCT
"MattB" <somedudeus@.yahoo.com> a crit dans le message de news:
40osodF1b4pklU1@.individual.net...
> Hi, I have a vb.net/asp.net 1.1 web application that may be used in other
> cultures where dates are formatted differently. I have three controls
> (either DropDowns or TextBoxes) one for year, one for month, and one for
> day.
> I'd like to be able to convert this to a DateTime type of variable and not
> have to rely on or find the localization settings.
> My idea was to populate the DateTime.Year, DateTime.Month and DateTime.Day
> from the controls, (like Date.Year = txtYear.Text) but those properties
> are read-only.
> I know I could make a string like "12-19-2005" and do a strDate.ToDateTime
> but that will break as soon as the application is used where dd-mm-yyyy is
> the norm.
> So If I have three variables representing year, month, and day what's the
> best way to convert to Date without relying on any kind of localization
> setting? Thanks!
> Matt
Daniel TIZON wrote:
> it works in ASPNET 2.0,
> it should work in ASP.NET1.x
> Dim MyDate As New DateTime(2005, 12, 19)
>
Perfect. Thanks!

String to date error

Hi guys Ive got a slight problem..

When i run my asp.net page through visual studio the application works fine, however when i puslish it and view it over myhttp://localhost page i get the following error "Conversion from string "28/8/2007" to type 'Date' is not valid." when selecting dates from a calendar control i created.

Im thinking this is some formatting issue having to do with EU/US Date format, however im not too sure about it and with a few research there are some help files stating to use globalization and once again im not sure how that works.

What im doing is assigning a date within an arraylist (which are of type dates) to a Date variable as below

Dim tempDate asDatetempDate = NewDate.Item(0) // arraylist of containing dates
Would appreciate some help regarding this issue

Thanks :)

It is a en-eu related problem. This article should help

http://msdn2.microsoft.com/en-us/library/2h3syy57.aspx
thanks that was interesting, also found out that the root to the problem was due to regional settings under the aspnet user account, my currently logged on account was set to UK however the user account aspnet was still on US therefore it kept showing dates in US format

String to Date conversion

Im trying to convert the input of several dropdownlists into a Date, but I can get an error and dont know how to convert these fields to a date type...
This is the code:
Dim BirthDate As DateTime = CType(ddlDay.SelectedValue + ddlMonth.SelectedValue + ddlYear.SelectedValue, Date)
And now im here anyways :p ...how can I calculate someones age when I have his birth date?

It would probably be best if you keep the two types the same. Try using this:

Dim BirthDate As DateTime = CType(ddlDay.SelectedValue & "/" & ddlMonth.SelectedValue & "/" & ddlYear.SelectedValue, DateTime)


Try using something like this, for the calculation (assuming a sub, based on a button's click event):

Sub getDiff(Source as Object, E as EventArgs)
Dim myBirth as DateTime
Dim sDate as String
Dim Age As Integer
sDate=ddMonth.SelectedItem.Value & "/" & ddDay.SelectedItem.Text & "/" & ddYear.SelectedItem.Text
myBirth=cDate(sDate)
Age=DateTime.Now.Year - myBirth.Year
If DateTime.Now.Month < myBirth.Month Or (DateTime.Now.Month = myBirth.Month And DateTime.Now.Day < myBirth.Day) Then
Age = Age - 1
End If
lblDate.text="Age=" & Age.ToString
End Sub

Check out full code sample:
http://aspnet101.com/aspnet101/aspnet/codesample.aspx?code=calcage


Hi Peter Smith,

Give the following a try. Example:

Dim tempAsString = ddlDay.SelectedValue + "/" + ddlMonth.SelectedValue + "/" + ddlYear.SelectedValue
Dim birthDateAs DateTime = DateTime.Parse(temp)

The following function can be used to calculate Age, given a BirthDate. Example:

Public Shared Function Age(ByVal dateOfBirth As DateTime) As Integer
If DateTime.Today.Month < dateOfBirth.Month Or DateTime.Today.Month = dateOfBirth.Month And DateTime.Today.Day < dateOfBirth.Day Then
Return DateTime.Today.Year - dateOfBirth.Year - 1
Else
Return DateTime.Today.Year - dateOfBirth.Year
End If
End Function

Hope this helps.

String To Decimal

Hi,

How can I convert from string (Text Box) to Decimal (addition some entries then get result)

Thanks,

http://tinyurl.com/aqpgm

To Decimal method.

Please can u write thz method

sorry for disturbing


cavalry wrote:

Please can u write thz method

Scroll down just a little bit on that link above and therz the method in both VB and C#


Hi again,

i see the like but

Access to the requested URL is not allowed!

there is a ristriction to it in my city, so plz copy a paste here

sorry again


thank u its DONE

i've Declare

Dim Grade1 as Double=Grade1.Text

Dim Grade2 as Double=Grade2.Text

Dim Grade as double = Grade1+Grade2

Thanks Alot

String to DateTime?

If i have this in my Database in a column of VARCHAR

2006/12/28 18:35:10

can i convert it to date time in C# ? I attempted this?

int

result =DateTime.Compare((DateTime)ds2.Tables[0].Rows[0].ItemArray[1], (DateTime)ds2.Tables[0].Rows[1].ItemArray[1]);

which basically is taking two values in that format and comparing them but i get a invalid cast exception. And importing them into SQL As datetime is not possible.

do i have to convert it to an int first? or strip out the "/" and the ":" ? is it even possible?

thanks in advance,

mcm

UseDateTime.TryParse.

Yeah Man,

worked like a charm.

mcm


you can use

Convert.ToDateTime(string)


Convert.ToDateTime produced the same cast error as my other attempt. by TryParse worked.

yay

String to equation

Got a quick question that I cannot get to work at work!

I have a field in SQL server that is set as a varchar but contains data like
>50 or <2 which is actually a target percentage. I have data in another
table stored as Decimal(14,2) that is the actual percentage. I need to
extract the two and create a conditional formatting result in a datalist.

Basically it would be something like this.

Assume actualpercentage = 30
targetpercentage = >50

If actual percentagetargetpercentage = True then forecolor= "Green"
Else
forecolor = "Red"

In actual terms it would be like
If 30>50 = True then forecolor = "Green"
Else
forecolor = "Red"

Don't worry about setting the color I can get that accomplished if I could
just build the boolean expression. And trust me I know the way it is written
here seems weird but it represents what I need to test. Basically the target
percentage is anything above 50% so I need to test and see if the actual was
greater than the target. However, like I show before the target could be
anything like <2%

Thanks for any help, a function or any mechanism for that matter would be
great.

Marty UHi Mary,

Obviously the first thing to do is to parse your varchar field. You stated
that your column "contains data like >50 or <2" - you need to get more
specific than that, becuase in essence, you have stored 2 different things
in the column, and the first thing you need is to split your string into 2
pieces. The only way to do that is to know what all of the possible values
for the first (comparison operator) is, so that you can identify where
tosplit the data. Of course, this would have been much easier if you had
used 2 columns to store the 2 values; that is good database design. But once
you've identified all the possible values of the first part, you can create
a loop that loops through all of them and uses the index of the last
character to determine where to split the value. Once split into 2 values,
you need to create a loop which selects from various kinds of comparison
operators that correspond to the ones in your list of possibles, and builds
a comparison statement from one of them.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Marty Underwood" <martman100@.insightbb.com> wrote in message
news:bczYb.341294$xy6.1700666@.attbi_s02...
> Got a quick question that I cannot get to work at work!
> I have a field in SQL server that is set as a varchar but contains data
like
> >50 or <2 which is actually a target percentage. I have data in another
> table stored as Decimal(14,2) that is the actual percentage. I need to
> extract the two and create a conditional formatting result in a datalist.
> Basically it would be something like this.
> Assume actualpercentage = 30
> targetpercentage = >50
> If actual percentagetargetpercentage = True then forecolor= "Green"
> Else
> forecolor = "Red"
> In actual terms it would be like
> If 30>50 = True then forecolor = "Green"
> Else
> forecolor = "Red"
>
> Don't worry about setting the color I can get that accomplished if I could
> just build the boolean expression. And trust me I know the way it is
written
> here seems weird but it represents what I need to test. Basically the
target
> percentage is anything above 50% so I need to test and see if the actual
was
> greater than the target. However, like I show before the target could be
> anything like <2%
> Thanks for any help, a function or any mechanism for that matter would be
> great.
> Marty U
>
Hi Marty,

Look at the String.Substring() method. It's overloaded. One version takes
one parameter, which is the starting index of the substring. It reads to the
end of the string. The other takes a second parameter which is the number of
characters to get. So, assuming that your data, as you said, has only 2
single-character comparison operators, you can get the 2 values from it by
using the String.Substring method(). Example:

Dim s As String = "<123"
Dim operator As String = s.Substring(0, 1)
Dim value As Integer = Convert.ToInt32(s.Substring(1))

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Marty U" <anonymous@.discussions.microsoft.com> wrote in message
news:8ABD3BD8-4FD3-456D-8DA0-722D75DCD452@.microsoft.com...
> Thanks for the reply Kevin,
> The only two comparison operators would be the greater than, less than
operators. I would have split these into two different columns but the
customer never said they would be used for actual comparisons but just a
display mechanism. Now I don't have time to redesign the related objects
that would use the split column.
> I had an idea of creating a function that receives 3 items.
> Function ShowResult(ActualValue as Decimal, theOperator as String,
TargetValue as Decimal)
> Dim theResult as Boolean
> theResult = ActualValuetheOperatorTargetValue
> Select Case theResult
> Case "True"
> do something
> Case "False"
> do something
> End Select
> End Function
> I would use a Left(TargetValue, 1) to pass theOperator argument. Can you
look at this theory and give me an idea how I can pass these 3 items into a
function and get the desired result of whether it's true or false.
> Thanks again, I don't have time to harp on this since I have a deadline of
Friday and this is just a perk they would like to have.
Sounds good I will look into this tomorrow at work. Oh and by the way I did
split the column into two seperate columns today due to another issue I had
that was not worth the trouble. It was easier to modify six pages of code
and modify the database then to program with the data being combined in the
DB.

Marty U

"Kevin Spencer" <kevin@.takempis.com> wrote in message
news:e2rCPxk9DHA.452@.TK2MSFTNGP11.phx.gbl...
> Hi Marty,
> Look at the String.Substring() method. It's overloaded. One version takes
> one parameter, which is the starting index of the substring. It reads to
the
> end of the string. The other takes a second parameter which is the number
of
> characters to get. So, assuming that your data, as you said, has only 2
> single-character comparison operators, you can get the 2 values from it by
> using the String.Substring method(). Example:
> Dim s As String = "<123"
> Dim operator As String = s.Substring(0, 1)
> Dim value As Integer = Convert.ToInt32(s.Substring(1))
> --
> HTH,
> Kevin Spencer
> .Net Developer
> Microsoft MVP
> Big things are made up
> of lots of little things.
> "Marty U" <anonymous@.discussions.microsoft.com> wrote in message
> news:8ABD3BD8-4FD3-456D-8DA0-722D75DCD452@.microsoft.com...
> > Thanks for the reply Kevin,
> > The only two comparison operators would be the greater than, less than
> operators. I would have split these into two different columns but the
> customer never said they would be used for actual comparisons but just a
> display mechanism. Now I don't have time to redesign the related objects
> that would use the split column.
> > I had an idea of creating a function that receives 3 items.
> > Function ShowResult(ActualValue as Decimal, theOperator as String,
> TargetValue as Decimal)
> > Dim theResult as Boolean
> > theResult = ActualValuetheOperatorTargetValue
> > Select Case theResult
> > Case "True"
> > do something
> > Case "False"
> > do something
> > End Select
> > End Function
> > I would use a Left(TargetValue, 1) to pass theOperator argument. Can you
> look at this theory and give me an idea how I can pass these 3 items into
a
> function and get the desired result of whether it's true or false.
> > Thanks again, I don't have time to harp on this since I have a deadline
of
> Friday and this is just a perk they would like to have.

String to Enumeration

Hello,

How do I convert a string an enumeration value?

I have the following Enum:

Public Enum MyEnum
Book = 1
Movie
End Enum

Basically, I have a variable of type MyEnum and I want to define a
value to it:

Dim MyString As String = "Book"
Dim MyVar As MyEnum = MyString

I am getting an error.
I then tried:
Dim MyVar As MyEnum = CType(MyString, MyEnum)

This is still not working.
Any idea of how to solve this?

Thanks,
MiguelFor outputing the string, just use MyEnum.ToString(). And to reverse the
operation, use Enum.Parse.

String to Enum

Hello,

How do I convert a string an enumeration value?

I have the following Enum:

Public Enum MyEnum
Book = 1
Movie
End Enum

Basically, I have a variable of type MyEnum and I want to define a value to it:

Dim MyString As String = "Book"
Dim MyVar As MyEnum = MyString

I am getting an error.
I then tried:
Dim MyVar As MyEnum = CType(MyString, MyEnum)

This is still not working.
Any idea of how to solve this?

Thanks,
Miguel

Here's how it's done in C# (should be similar for VB)

enum EType {AAA, BBB, CCC};protected void Button1_Click(object sender, EventArgs e) { EType Test; Test = (EType)Enum.Parse(typeof(EType),"AAA"); }

Hello,

Here is a sample for you:

Imports SystemPublicClass ParseTest <FlagsAttribute()> _Enum Colors Red = 1 Green = 2 Blue = 4 Yellow = 8EndEnumPublicSharedSub Main() Console.WriteLine("The entries of the Colors Enum are:")Dim colorNameAsStringForEach colorNameIn [Enum].GetNames(GetType(Colors)) Console.WriteLine("{0}={1}", colorName, Convert.ToInt32([Enum].Parse(GetType(Colors), colorName)))Next colorName Console.WriteLine()Dim myOrangeAs Colors = CType([Enum].Parse(GetType(Colors),"Red, Yellow"), Colors) Console.WriteLine("The myOrange value {1} has the combined entries of {0}", myOrange, Convert.ToInt64(myOrange))EndSubEndClass'This code example produces the following results:''The entries of the Colors Enum are:'Red=1'Green=2'Blue=4'Yellow=8''The myOrange value 9 has the combined entries of Red, Yellow'
More details are here:http://msdn2.microsoft.com/en-us/library/essfb559.aspx

string to formated datetime

how can I convert a string like this "10/04" meaning octuber/2004 to a valid
DateTime?
"Alejandro Penate-Diaz" wrote:

> how can I convert a string like this "10/04" meaning octuber/2004 to a valid
> DateTime?
>
CDate function:

http://msdn.microsoft.com/library/d.../vsfctcdate.asp

Check the parameters that CDate is expecting. You may need to do some text
parsing and string manipulation before calling CDate.
You will use the .ParseExact method of DateTime.

Dim dt as DateTime
dt = DateTime.Parse( "10/04", "MM/yy" )

DateTime dtC = DateTime.Parse( "10/04", "MM/yy" );

HTH,

bill

"Alejandro Penate-Diaz" <alexware69@.hotmail.com> wrote in message
news:%23dwiz$jJFHA.2136@.TK2MSFTNGP14.phx.gbl...
> how can I convert a string like this "10/04" meaning octuber/2004 to a
valid
> DateTime?

string to formated datetime

how can I convert a string like this "10/04" meaning octuber/2004 to a valid
DateTime?
"Alejandro Penate-Diaz" wrote:

> how can I convert a string like this "10/04" meaning octuber/2004 to a val
id
> DateTime?
>
>
CDate function:
http://msdn.microsoft.com/library/d.../>
ctcdate.asp
Check the parameters that CDate is expecting. You may need to do some text
parsing and string manipulation before calling CDate.
You will use the .ParseExact method of DateTime.
Dim dt as DateTime
dt = DateTime.Parse( "10/04", "MM/yy" )
DateTime dtC = DateTime.Parse( "10/04", "MM/yy" );
HTH,
bill
"Alejandro Penate-Diaz" <alexware69@.hotmail.com> wrote in message
news:%23dwiz$jJFHA.2136@.TK2MSFTNGP14.phx.gbl...
> how can I convert a string like this "10/04" meaning octuber/2004 to a
valid
> DateTime?
>

String to html conversion

I want to send an email in html format through code. Problem I am having is converting the string into html without and grumps. Does .net have a class that converts this easily. I have tried doing a search and replace chracters, but still having issues. Or has anyone done anything similar?

BC

hi bcanonica,

do you have some sample code on you that i could look into?

regards,

zee


Hello,

By default, email sent with System.Net.Mail is formatted as plain text. To format as Html, set the MailMessage.IsBodyHtml property to true.

[ C# ]

 //create the mail message MailMessage mail = new MailMessage(); //set the addresses mail.From = new MailAddress("me@.mycompany.com"); mail.To.Add("you@.yourcompany.com"); //set the content mail.Subject = "This is an email"; mail.Body = "this is a sample body with html in it. <b>This is bold</b> <font color=#336699>This is blue</font>"; mail.IsBodyHtml = true; //send the message SmtpClient smtp = new SmtpClient("127.0.0.1"); smtp.Send(mail);


[ VB.NET ]

 'create the mail messageDim mail As New MailMessage()'set the addressesmail.From = New MailAddress("me@.mycompany.com")mail.To.Add("you@.yourcompany.com")'set the contentmail.Subject = "This is an email" mail.Body = "this is a sample body with html in it. <b>This is bold</b> <font color=#336699>This is blue</font>"mail.IsBodyHtml = True'send the messageDim smtp As New SmtpClient("127.0.0.1")smtp.Send(mail)

Not exactly what I was looking for. I want to know how I can convert an html email that I create in Publisher to to a string so I can send it in the body of mailMessage object. Is their a namespace that converts from a string to html and vis versa. Meaning using quotes and other characters that do not match.

BC


You can useServer.HtmlEncode and alsoHttpServerUtility.HtmlEncode Method andHttpServerUtility.HtmlDecode Method.

Here still is another way to do such things:Rendering a control as an Html String

HTH

string to integer

Hello

I need to do something like this, read data from text file and use it as integer. How can I do it?

Please help me...

Artur

myString = "1234"

myInt = CInt(myString)


Is the text that you are retrieving strictly a number, or is it a combination of text and numbers where you only want to get the numbers? If it's just numbers, you can use Integer.Parse() in VB.NET or int.Parse() in C#.

To read a text file, you use the System.IO namespace. The TextReader Class on MSDN has an example of using a TextReader to get the contents of a text file.

TextReader Class

If the variable m_Text contained the contents of the text file, then here is how you would use Integer.Parse:

VB.NET
Dim m_NumberAs Integer
m_Number =Integer.Parse(m_Text)

C#
int m_Number;
m_Number =int.Parse(m_Text);

HTH


If you are expecting it to be numbers either of the ways above will work however if you try to cast you might want to wrap it in a try to catch any problems in case someone does put in non number data

String to Int error

Hello,

I need to convert a value from my textbox from string to int. It only hold the idea of an item and i need to send that as Stored Procedure value to fetch another value.
I now get the current error:

Input string was not in a correct format.

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: Input string was not in a correct format.

Source Error:

Line 97: Dim strComm As String = "spQMelderStatusGet"
Line 98: Dim str As String = Convert.ToString(lblStatus.Text)
Line 99: Dim ID As Int32 = Int32.Parse(str)
Line 100: Using loStat As SqlCommand = New SqlCommand(strComm)
Line 101:


Source File:D:\Source\Qualm\QMelder\StatusViewer.aspx.vb Line:99

And this is the code i'm using:

'Get status naamDim strCommAs String ="spQMelderStatusGet"Dim strAs String = Convert.ToString(lblStatus.Text)
Dim IDAs Int32 = Int32.Parse(str)
Using loStatAs SqlCommand =New SqlCommand(strComm)

Dim StatIDAs New SqlParameter()
StatID.ParameterName ="@dotnet.itags.org.StatusID" StatID.SqlDbType = SqlDbType.Int StatID.Direction = ParameterDirection.InputOutput StatID.Size = 2 StatID.Value = ID loStat.Parameters.Add(StatID) loStat.Connection = loConn loStat.CommandType = CommandType.StoredProcedure statReader = loStat.ExecuteReader lblStatus.Text = statReader("StatusNaam")
End Using

statReader.Close()


I've tried all kinds of ways, like converting the txtbox value to string and then to int but keep giving the same error, so most likely those codes weren't the right ones either.

If someone could help me out, tnx alot in advance.

Anoiks

Hi

before parsing String value in integer, check it's value ..

i hope . in ur case it's value is NULL or any Literal word


Hi

Hope I have understood your problem correctly.

Have you tried Convert.ToInt32("string").

But as I write, If the parse function you used fails to convert the string to integer, then may be the value entered in the text box either is non-convertible to integer data type or a conversion results in a out of range value. If you beleive it is a large integer value, can you try using a "float" or a "double" data type.

Worse case, can you convert your stored procedure type to accept an integer, I hope that is not hindering your requirement.

VJ


ok that was a stupid mistake, thanks alot i was too focussed on that part of code.
So i didnt notice i didnt fill the string in codes before that.Geeked

String to integer conversion

Hello!

Class int has a method for conversion numeric values to strings (ToString() method). Is there any similar method or function, which converts a string into Int32 type?

Cheers!static method System.Int32.Parse()
Thanks!
Hello!

I tried to use the method you gave me, but got an error message: "System.FormatException: Input string was not in a correct format."
Maybe there is any special way I should use it?

Here's how I do it:


void Fill_End_Day(int auto, int aasta, int kuu, int paev) {
autorent.broneering wsProxy = new autorent.broneering();
System.Data.DataSet ds;
ds = wsProxy.JargmineHyiv(auto, aasta, kuu, paev);
int i;
for (i=paev; i<System.Int32.Parse(ds.Tables[0].Rows[0]["paev"].ToString()); i++)
DropDownList7.Items.Add(i.ToString());
}

Is there something wrong with it?

Cheers.
c# doesn't have cInt()?
I'm afraid it doesn't. Maybe there is some similar function, but I can't even assume in which class I should seek for it.
Sorry, it works now! It should have worked from the beginning, but there has been a stupid mistake in another palce.
Thank you!

string to object

Basically I have a class called Dog and when using the objectdatasource I
can use a string parameter to pass into the selectmethod. so I pass in a
string = 'Dog' now once in the selectmethod I need to convert that string
into and object of type Dog...I hope this makes sense. Do anyone know how to
do this' i guess I need a similar method to Eval in javascript.
Please need urgent so could replies also go to johncotsell@dotnet.itags.org.hotmail.com
cheers John"John Cotsell" <john.cotsell@.formicary.net> wrote in
news:epLI7fRHGHA.1192@.TK2MSFTNGP11.phx.gbl:

> Basically I have a class called Dog and when using the
> objectdatasource I can use a string parameter to pass into the
> selectmethod. so I pass in a string = 'Dog' now once in the
> selectmethod I need to convert that string into and object of type
> Dog...I hope this makes sense. Do anyone know how to do this'
System.Type.GetType can return objects based on Type.

> Please need urgent so could replies also go to johncotsell@.hotmail.com
If you post on Usenet, check on Usenet.
Stan Kee (spamhoneypot@.rogers.com)
For equivalent to javascript's eval, check out the namespaces
System.Reflection.Emit (for creating assemblies on-the-fly) or perhaps
Microsoft.CSharp.Compiler (try the static Compile() method)

string to object

Hi

How to convert string to object?

i.e.

string objname = "Control1"

then some how use (function or method)

objname.visible = false

Hi There,

asmgx:

How to convert string to object?

i.e.

string objname = "Control1"

then some how use (function or method)

objname.visible = false

You can assign string value to object

e.g

string value = "control1";

object obj = value;

But not using string value to identify as object.

However, you can use string value as id and find the control.

e.g

Say you wanted to get textbox with id myTextBox

TextBox txt = (TextBox)this.FindControl("myTextBox"); //


in c#

String obj ="Control1";

Object objCast = ((Object)obj);

in vb

Dim objAsString = "Control1"

Dim objCastAsObject = (CType(obj,Object))

asmgx:

then some how use (function or method)

objname.visible = false

what exact you want to do?

string to object

Basically I have a class called Dog and when using the objectdatasource I
can use a string parameter to pass into the selectmethod. so I pass in a
string = 'Dog' now once in the selectmethod I need to convert that string
into and object of type Dog...I hope this makes sense. Do anyone know how to
do this?? i guess I need a similar method to Eval in javascript.

Please need urgent so could replies also go to johncotsell@dotnet.itags.org.hotmail.com

cheers JohnFor equivalent to javascript's eval, check out the namespaces
System.Reflection.Emit (for creating assemblies on-the-fly) or perhaps
Microsoft.CSharp.Compiler (try the static Compile() method)

String to Object?

Hi:

Can I convert a string to an object?

In my system I have the following:

Document.Title.Contains("Sony Camera")

The above returns an object of type Criterion, however, it will be saved in database,

when i read the above line as string, i want to make it an object of type Criterion, is this possible?

thank you.

Hi

(objectName) Document.Title.Contains("Sony Camera")

or

object.parse(Document.Title.Contains("Sony Camera"));


Hi

Thanks for the reply.

Don't I need any reflection? Just guessing.

Thanks,

string to string[]

Hi,

I've got this code :


string[] Params;

string SQL = "SELECT * FROM T_MANAGEMENT_PAGES";
SqlCommand myCommand = new SqlCommand(SQL, myConnection);
myConnection.Open();
SqlDataReader myReader = myCommand.ExecuteReader();

try
{
while (myReader.Read())
{
Params_Type = myReader.GetValue(0).ToString();
}
}
catch
{
}
finally
{
}
myReader.Close();

My problem is to obtain Params_Type.
But each time, it says : "impossible to convert '[object]' in 'string[]' "

Thanks for all.
SébHello, try this instead:


int i = 0;
while (myReader.Read())
{
Params_Type[i] = myReader.GetValue(0).ToString();
i++;
}

Hope this works fine for u.
Yes but, in my database I have in one column :
{"BURE_ETUD_ID","LANG_ID","LANG_NAME"}

My sql return only one line.

and what I want is :


string[] Params = {"BURE_ETUD_ID","LANG_ID","LANG_NAME"};

Thanks
Séb
You should, ideally, rework your database. This is not a great layout. You should have a table that links to this record and has one row per entry to allow you to better get at the data.

Given the string returned as it is, you could use String.Split() to create a string array.
I Agree with you, but is there any possibility to convert one string in one string[] ?

Séb
Yes. As I mentioned in my last post: the String class has a Split() method. Please look at the docs.
I'm sorry, i haven't see the end of your message.

Thanks for your heulp

Regards

Séb
Hello,
I believe yes, you should rework ur database, each value should be in one column. this is typical !!!
then, after u rework ur database, use the code i gave, it works just fine.

Good Luck.

string to string[]

string[] strArray;while(dtardrUsrDet.Read())

{

string strUsrEmail=dtardrUsrDet.GetValue(0).ToString();

int intDayDiff=System.Convert.ToInt16(dtardrUsrDet.GetValue(1).ToString());

if(intDayDiff==45)

{

strArray=strUsrEmail;

}

if(intDayDiff==30)

{

strArray=strUsrEmail;

}

how to store string values from reader into string array

Hi,

I am assuming that you want each string in an array, not each character as a separate string in a string array here...

The easiest way is to create an ArrayList, add each string to that (within a while loop to read each record from the DataReader) and then use the ToArray() method, passing the type that you want the array to be (i.e string in your case).

In .net 2.0, you would use a generic List<string> collection, which gives you the advantage of strong typing on the collection.

Rich


string[] strArray;

Int i=0;

while(dtardrUsrDet.Read())

{

string strUsrEmail=dtardrUsrDet.GetValue(0).ToString();

int intDayDiff=System.Convert.ToInt16(dtardrUsrDet.GetValue(1).ToString());

if(intDayDiff==45 ||intDayDiff==30)

{

Array.Resize(refstrArray, i);
strArray[i] =strUsrEmail;

i++;

}

}

hope this helps./.

String Tokenizer

Hi All,
Is there any string tokenizer in .net 2.0 just like in Java?
Regards,
GunOn Mar 15, 8:05 am, "Gunawan" <jgun98.mi...@.gmail.com> wrote:
> Hi All,
> Is there any string tokenizer in .net 2.0 just like in Java?
> Regards,
> Gun
There is no standard implementation, and you can either use
String.Split, or an own class, e.g.
http://msdn2.microsoft.com/en-us/library/aa288462(VS.71).aspx

String Tokenizer

Hi All,
Is there any string tokenizer in .net 2.0 just like in Java?
Regards,
GunOn Mar 15, 8:05 am, "Gunawan" <jgun98.mi...@.gmail.comwrote:

Quote:

Originally Posted by

Hi All,
Is there any string tokenizer in .net 2.0 just like in Java?
Regards,
Gun


There is no standard implementation, and you can either use
String.Split, or an own class, e.g.

http://msdn2.microsoft.com/en-us/li...462(VS.71).aspx

string to xhtml

Is there a way to take a string and make it xhtml compliant? The string may contain ampersand and non breaking spaces ( ). My ajax response is bombing on a string containing a non breaking space ( ). So, is there a function that will take a string as input and return it as valid xhtml?

You can try Server.HTMLEncode( string )

http://msdn2.microsoft.com/en-us/library/ms525347.aspx

I don't see how it would blow up on the " " because there is nothing invalid about this, specifically in regards to Xhtml.

Other than that you are probably going to have to write your own function to replace characters properly.


I discovered that XML does not recognize . Instead, you have to add a document type to the top of your XML:

<!DOCTYPE stylesheet [<!ENTITY nbsp " ">

This fixes the problem.

String -tostring

hi

what is actually difference between string and To string?when it used in which condition?

Hi,

String is a type whileToString() is a method on the Object class.

Grz, Kris.


Ok, XIII. I agree with you

I'm surethat's a relief.

String Tokenizing with ASP.NET?

Hi all,

I am somewhat new to the DOTNET world and I am wondering if there is an easy way to tokenize strings using asp.net.

With java, this is done quite easilly, but I have not seen anything in the .net class libraries that would work the same.

Any help is appreciated!

_Luke Dubya
_minneapolisOkay I'll be more specific:

I have cookies that have several values seperated by a comma ","

I want to parse the values into seperate tokens so I can then run a SQL statement with several OR statements to return the results in my datagrid.

the values of my cookies are product ids.

example: 4322-001,E322,8000DN,4317-001

Then I want to turn this into a sql statement:

SELECT * FROM sometable WHERE productid="4322-001" OR WHERE productid="E322" etc...

so thats what I'm trying to do. any ideas or help is much appreciated.

Thanks all!

_Luke Dubya
_Minneapolis
Substrings seems the best way to go (assume that you dont know how many product numbers you have in the cookie).

<a href"http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemstringclasssubstringtopic.asp">Here</a> is a link to set you off.

You want something on the lines of:


Dim cookieString as string = ......(get the cookie string)
Dim sqlStatement = "SELECT * FROM sometable "

if ( there is a "," in the cookieString)
{
sqlStatement += " WHERE productid = " & cookieString.substring(...)
cookieString = cookieString.substring(...) 'get rid of the first product and ","
}

where ( there is a "," in the cookieString)
{
sqlStatement += " OR WHERE productid = " & cookieString.substring(...)
cookieString = cookieString.substring(...) 'get rid of the first product and ","
}

HTH

Jagdip

String Tokenizing

Hello,

I want to do simple string tokenizing and am able to do it in JAVA using String Tokenizer Class. Can you help me how i can do the same in ASP.NET 1.1 (VB.NET).

I want to tokenize a simple string like below based on pipeline character.

string1|string2|string3

Hope for some response,

Thanks.
Imran.

See if this might help:

http://www.awprofessional.com/articles/article.asp?p=169471&seqNum=5

String Trancate

Hi,

In following example I would like to Trancate first 5 digits and last 3 digits.

W04056040-PAY001

So I can get 6040-PAY

Any code behind examples?

Any help will be appriciated.

Thanks.

TekinUse the stringbuilder class (remove method):

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemtextstringbuildermemberstopic.asp

Or if you want to do it old school, the intrinsic Mid function works well too.
Hi mtekin303,

There's many ways to solve this problem. Here's two ideas:


[Visual Basic]
Dim temp As String = "W04056040-PAY001"
Response.Write("Sample 1: " + temp.Substring(5,8) + "<br />")
Response.Write("Sample 2: " + temp.Remove(temp.Length-3,3).Remove(0,5))

[C#]
string temp = "W04056040-PAY001";
Response.Write("Sample 1: " + temp.Substring(5,8) + "<br />");
Response.Write("Sample 2: " + temp.Remove(temp.Length-3,3).Remove(0,5));


Hope this helps.
Thank you.

Stringbuilder resolved it.

Thanks again.
Thanks Chuck.

Stringbuilder resolved it.

String validation in C#?

I'm a 30 year codingveteran using mostly S370 Assembler and Pascal on the PC's. I'm gettingmy feet wet in C#, and having a dickens of a time figuring out trivialthings. The crisis de jour is determining if a string is "valid" beforeletting XML barf all over it for containing a Hex 06 or some such.
In Pascal, I'd define a constant, ValidChars:
ValidChars = ['0'..'9', 'A'..'Z', 'a'..'z', #5, #10, #13];

andsimply iterate over the string (The lightbulb is [ i ] - How do you escape emoticon stringsin this editor?):
for i := 1 to length(arg) do
if argIdea [I] not in ValidChars
then begin
<bad string stuff>
break;
end;

I can't find anything about sets in the C# doc, so maybe theINpredicate isn't going to fly. So, maybe a CASE statement on theordinals of the various characters. Nope, no case statement. There's aswitch, but it appears not to like case definitions of> " ". Maybe it's there but I can't figure out (other than 255 cases!) how to use it.
Note, I'm looking for "the C# way", for anelegantsolution. I went to find the ord (ordinal) function, and see I didn'teven have a list of string functions, char functions, or functions ingeneral (that I could find). It must be in there somewhere.Obviously, the "language" is just the bnf of the symbols and justa few rules about operators, etc.. But the "reality" is that functions,methods, properties, etc. are built into what MS distributes, and theremust be doc on these things somewhere. I can WRITE an ordfunction, but I'm certain I'd be duplicating some efforts built intothe distribution.
TheInElegant solution I have running is pretty ugly.

private string CheckData(string arg, bool debug)
{ int loop1;
bool valid = true;
for (loop1=0; loop1 < arg.Length; loop1++)
if ((arg[loop1] != "\t"[0])
&(arg[loop1] != "\r"[0])
&(arg[loop1] != "\n"[0])
&(arg[loop1] < " "[0]))
{ valid = false;
break;
}
if (valid)
return arg;
else if (debug)
return "|Invalid String|";
else
return "";
}

Maybethis is the best C# can do, but I sincerely doubt it. It's 35 yearsPascal's junior, it should have some elegance built-in!
Possiblythere is a web reference or even a book someone might suggest to getover the odd organization of the language doc in .Net.
tiaUse regular expressions...

EDIT
You use Regular Expression to do validations. To your other questions Predicates are in standard Arrays and all the Math functions are under System.Math but I think the class is Sealed. Try the links below for the FCL(framework class library) 2.0 and a free book that covered all the math functions in C#. A good book try Programming .NET by Jeff Prosise. I did not cover the string functions, they are under strings and formatting, run a search on MSDN because it takes a book chapter to cover. Hope this helps.
http://beta.asp.net/QuickStartv20/util/classbrowser.aspx

http://www.brpreiss.com/books/opus6/html/page10.html

string variable containing one doublequote

hallo,

how do I declare a string variable containing one doublequote?

this sentence should be in the variable: <img src="http://pics.10026.com/?src=

I was trying something ilke

Dim Path as string = "<img src="http://pics.10026.com/?src= & """ but doesn' work

any idea? thanks

reply to myself: found out the solution

chr(34) instead of """


Dim Path as string = "<img src="http://pics.10026.com/?src= & """"

'/

Dim Path as string = "<img src="http://pics.10026.com/?src=""

'/

Dim Path as string = "<img src="http://pics.10026.com/?src= & Chr(34)

:)

string vs stringbuilder

What can I better use?

StringBuilder sb =newStringBuilder();

sb.Append("SELECT ");

sb.Append("count(*) ");

sb.Append("FROM ");

sb.Append("table");

Or

query ="SELECT count(*) FROM table";

Look String is immutual object . you can't perform modification operation but in Stringbuilder is New type of Collection Class that provide feasibility to modify and other string operation without losing value


Hi

Strings of type System.String are immutable in .Net. That means any change to a string cause the runtime to create new string and abandon old one.

That happens invisibly, and many programmers might be surprised that following code allocate four new string in memory:

string s;

s = "select "; // "select"

s += " * from "; // "select * from"

s += " tablename"; // "select * from tablename"

Only the last string has a reference, the other two will be disposed of during garbage collection. Avoiding these types of temporary string helps avoid unnecessary garbage collection, which improve performance.

Use StringBuilder class to create dynamic (mutable) strings.

StringBuilder can span multiple statements. The default constructor creates a buffer of 16 bytes long, which grows as needed. You can specify an initial size and a maximum size if you like.

As in your case, if you do not need to break statement in query thanstringworks. Use StringBuilder when you want to span your query in multiple statement.

Hope this helps you.

Regards,

Mustakim Mansuri



If thats the case it better to use String because you did your query is simple BUT if you are trying to DO Insert with multiple values then you can use the StringBuilder to append values...

Just a little Gee-Whiz info as to how much better StringBuilder can be when you are making several concatenations (especially in a loop):

I was building an HTML string in a while(datareader.Read()) loop, and setting a divs InnerHtml equal to that string at the end. I didn't know any better, I never heard of StringBuilder. Then I came across an article about it, so I figured I'd give it a try. In one of my examples, I had about 1000 rows being returned and was making maybe 2 string concatenations within each iteration of the loop. Needless to say, it was running a little slow (between 3-5 seconds each time the user tried to access the page). After replacing straight string concatenations with StringBuilder.Append() statements, the page loaded almost immediately. A few seconds saved was pretty nice, but what further drove the importance home for me was when I remembered that the database connection was open that whole time. Multiply that by several users hitting the site at the same time, and it became very clear.

String vs. string in C#

Ok...

what's the difference? If I have functions like this...

public string foo(string bar)
{
}

public String foo(String bar)
{
}

I get an error saying that they are the same function... actually it says that foo is already defined, but..., so they must be equivalent. So, why do they both exist? Why does code code completion give you the capitalized version, but syntax hilighting recognizes the lowercase?Hi,

they are one and the same. Lowercase 'string' is C# shortcut/specific to System.String (the capitalized one e.g 'String').

String was not recognized as a valid Boolean

Why am I getting this error for Budget?

Error: An exception of type 'System.FormatException' occurred in
mscorlib.dll but was not handled in user code

Additional information: String was not recognized as a valid Boolean.

Public Sub UpdateCustomer_DashboardGraphs(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("lblCustomerID"), Label).Text.Trim()

'//--Textboxes
Dim intBudget As Integer
Try
intBudget = CType(CType(gvr.FindControl("txtBudget"),
TextBox).Text.Trim(), Int32)
Catch
intBudget = CType(0, Int32)
End Try

'//--Checkboxes
Dim intCurrentMonthCollections As Boolean =
CType(gvr.FindControl("chbx_CurrentMonthCollections"), CheckBox).Checked
Dim intRevenueByMonth As Boolean =
CType(gvr.FindControl("chbx_RevenueByMonth"), CheckBox).Checked
Dim intPDCsCCsMonthly As Boolean =
CType(gvr.FindControl("chbx_PDCsCCsMonthly"), CheckBox).Checked
Dim intRevenueByClient As Boolean =
CType(gvr.FindControl("chbx_RevenueByClient"), CheckBox).Checked

'//--Assign UpdateParameters
If intCurrentMonthCollections = True Then

ds_dashboard.UpdateParameters("CurrentMonthCollections").DefaultValue = 1
Else

ds_dashboard.UpdateParameters("CurrentMonthCollections").DefaultValue = 0
End If
...

ds_dashboard.UpdateParameters("Budget").DefaultValue =
intBudget

ds_dashboard.Update()
End If
Next
End Sub
--
dba123which line is the error on?

Karl

--
http://www.openmymind.net/

"dba123" <dba123@.discussions.microsoft.com> wrote in message
news:0FCAE9F2-E68A-4794-9A68-BAF5877BA533@.microsoft.com...
> Why am I getting this error for Budget?
> Error: An exception of type 'System.FormatException' occurred in
> mscorlib.dll but was not handled in user code
> Additional information: String was not recognized as a valid Boolean.
>
> Public Sub UpdateCustomer_DashboardGraphs(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("lblCustomerID"), Label).Text.Trim()
> '//--Textboxes
> Dim intBudget As Integer
> Try
> intBudget = CType(CType(gvr.FindControl("txtBudget"),
> TextBox).Text.Trim(), Int32)
> Catch
> intBudget = CType(0, Int32)
> End Try
> '//--Checkboxes
> Dim intCurrentMonthCollections As Boolean =
> CType(gvr.FindControl("chbx_CurrentMonthCollections"), CheckBox).Checked
> Dim intRevenueByMonth As Boolean =
> CType(gvr.FindControl("chbx_RevenueByMonth"), CheckBox).Checked
> Dim intPDCsCCsMonthly As Boolean =
> CType(gvr.FindControl("chbx_PDCsCCsMonthly"), CheckBox).Checked
> Dim intRevenueByClient As Boolean =
> CType(gvr.FindControl("chbx_RevenueByClient"), CheckBox).Checked
> '//--Assign UpdateParameters
> If intCurrentMonthCollections = True Then
> ds_dashboard.UpdateParameters("CurrentMonthCollections").DefaultValue = 1
> Else
> ds_dashboard.UpdateParameters("CurrentMonthCollections").DefaultValue = 0
> End If
> ...
> ds_dashboard.UpdateParameters("Budget").DefaultValue =
> intBudget
> ds_dashboard.Update()
> End If
> Next
> End Sub
> --
> dba123
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:DashboardConn %>"
SelectCommand="aspx_Get_Customer_DashboardGraphs"
SelectCommandType="StoredProcedure"
UpdateCommand="aspx_Update_Customer_DashboardGraphs"
UpdateCommandType="StoredProcedure"
<UpdateParameters>
<asp:Parameter Name="CustomerID" Type="Int32" />
<asp:Parameter Name="Budget" Type="Int32" />
<asp:Parameter Name="CurrentMonthCollections"
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"></HeaderStyle>
<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"></HeaderStyle>
<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"></HeaderStyle>
<ItemTemplate>
<asp:checkbox runat="server"
Id="chbx_CurrentMonthCollections" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Revenue By Month"
SortExpression="Name" ItemStyle-HorizontalAlign="Center">
<HeaderStyle HorizontalAlign="center"></HeaderStyle>
<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"></HeaderStyle>
<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"></HeaderStyle>
<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_Customer_DashboardGraphs]

@.CustomerIDbigint,
@.Budgetint,
@.CurrentMonthCollectionsbit,
@.RevenueByMonthbit,
@.PDCsCCsMonthlybit,
@.RevenueByClientbit

AS
BEGIN

UPDATE dbo.Customer_DashboardGraphs
SET Budget = @.Budget,
CurrentMonthCollections = @.CurrentMonthCollections,
RevenueByMonth = @.RevenueByMonth,
PDCsCCsMonthly = @.PDCsCCsMonthly,
RevenueByClient = @.RevenueByClient
WHERE Customer_DashboardGraphs.Customer = @.CustomerID
END

My Table Schema:
--------

CREATE TABLE [dbo].[Customer_DashboardGraphs](
[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.UpdateParameters("Budget").DefaultValue = intBudget
Line 54:
Line 55: ds_dashboard.Update()
Line 56: End If
Line 57: Next

Source File:
Y:\inetpub\wwwroot\apex\webapps\dashboard\dashboar d\index.aspx.vb Line: 55

Stack Trace:
------

[FormatException: String was not recognized as a valid Boolean.]
System.Boolean.Parse(String value) +2709172
System.String.System.IConvertible.ToBoolean(IForma tProvider provider) +12
System.Convert.ChangeType(Object value, TypeCode typeCode,
IFormatProvider provider) +98
System.Web.UI.WebControls.Parameter.GetValue(Objec t value, String
defaultValue, TypeCode type, Boolean convertEmptyStringToNull, Boolean
ignoreNullableTypeChanges) +257
System.Web.UI.WebControls.Parameter.get_ParameterV alue() +91
System.Web.UI.WebControls.ParameterCollection.GetV alues(HttpContext
context, Control control) +282

System.Web.UI.WebControls.SqlDataSourceView.Initia lizeParameters(DbCommand
command, ParameterCollection parameters, IDictionary exclusionList) +344
System.Web.UI.WebControls.SqlDataSourceView.Execut eUpdate(IDictionary
keys, IDictionary values, IDictionary oldValues) +449
System.Web.UI.WebControls.SqlDataSourceView.Update (IDictionary keys,
IDictionary values, IDictionary oldValues) +37
System.Web.UI.WebControls.SqlDataSource.Update() +42
dashboard._Default.UpdateCustomer_DashboardGraphs( Object sender,
EventArgs e) in
Y:\inetpub\wwwroot\sss\webapps\dashboard\dashboard \index.aspx.vb:55
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +96
System.Web.UI.WebControls.Button.RaisePostBackEven t(String eventArgument)
+116

System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +31
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +32
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +72
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3837

--
dba123

"Karl Seguin [MVP]" wrote:

> which line is the error on?
> Karl
> --
> http://www.openmymind.net/
>
> "dba123" <dba123@.discussions.microsoft.com> wrote in message
> news:0FCAE9F2-E68A-4794-9A68-BAF5877BA533@.microsoft.com...
> > Why am I getting this error for Budget?
> > Error: An exception of type 'System.FormatException' occurred in
> > mscorlib.dll but was not handled in user code
> > Additional information: String was not recognized as a valid Boolean.
> > Public Sub UpdateCustomer_DashboardGraphs(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("lblCustomerID"), Label).Text.Trim()
> > '//--Textboxes
> > Dim intBudget As Integer
> > Try
> > intBudget = CType(CType(gvr.FindControl("txtBudget"),
> > TextBox).Text.Trim(), Int32)
> > Catch
> > intBudget = CType(0, Int32)
> > End Try
> > '//--Checkboxes
> > Dim intCurrentMonthCollections As Boolean =
> > CType(gvr.FindControl("chbx_CurrentMonthCollections"), CheckBox).Checked
> > Dim intRevenueByMonth As Boolean =
> > CType(gvr.FindControl("chbx_RevenueByMonth"), CheckBox).Checked
> > Dim intPDCsCCsMonthly As Boolean =
> > CType(gvr.FindControl("chbx_PDCsCCsMonthly"), CheckBox).Checked
> > Dim intRevenueByClient As Boolean =
> > CType(gvr.FindControl("chbx_RevenueByClient"), CheckBox).Checked
> > '//--Assign UpdateParameters
> > If intCurrentMonthCollections = True Then
> > ds_dashboard.UpdateParameters("CurrentMonthCollections").DefaultValue = 1
> > Else
> > ds_dashboard.UpdateParameters("CurrentMonthCollections").DefaultValue = 0
> > End If
> > ...
> > ds_dashboard.UpdateParameters("Budget").DefaultValue =
> > intBudget
> > ds_dashboard.Update()
> > End If
> > Next
> > End Sub
> > --
> > dba123
>
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.UpdateParameters("CurrentMonthCollections").DefaultValue = 1
Else

ds_dashboard.UpdateParameters("CurrentMonthCollections").DefaultValue = 0
End If

to

If intCurrentMonthCollections = True Then

ds_dashboard.UpdateParameters("CurrentMonthCollections").DefaultValue = "true"
Else

ds_dashboard.UpdateParameters("CurrentMonthCollections").DefaultValue =
"false"
End If

The error goes away but it's still not updating those bit fields in my table

--
dba123

"dba123" wrote:

> 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:DashboardConn %>"
> SelectCommand="aspx_Get_Customer_DashboardGraphs"
> SelectCommandType="StoredProcedure"
> UpdateCommand="aspx_Update_Customer_DashboardGraphs"
> UpdateCommandType="StoredProcedure"
> >
> <UpdateParameters>
> <asp:Parameter Name="CustomerID" Type="Int32" />
> <asp:Parameter Name="Budget" Type="Int32" />
> <asp:Parameter Name="CurrentMonthCollections"
> 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"></HeaderStyle>
> <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"></HeaderStyle>
> <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"></HeaderStyle>
> <ItemTemplate>
> <asp:checkbox runat="server"
> Id="chbx_CurrentMonthCollections" />
> </ItemTemplate>
> </asp:TemplateField>
> <asp:TemplateField HeaderText="Revenue By Month"
> SortExpression="Name" ItemStyle-HorizontalAlign="Center">
> <HeaderStyle HorizontalAlign="center"></HeaderStyle>
> <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"></HeaderStyle>
> <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"></HeaderStyle>
> <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_Customer_DashboardGraphs]
> @.CustomerIDbigint,
> @.Budgetint,
> @.CurrentMonthCollectionsbit,
> @.RevenueByMonthbit,
> @.PDCsCCsMonthlybit,
> @.RevenueByClientbit
> AS
> BEGIN
> UPDATE dbo.Customer_DashboardGraphs
> SET Budget = @.Budget,
> CurrentMonthCollections = @.CurrentMonthCollections,
> RevenueByMonth = @.RevenueByMonth,
> PDCsCCsMonthly = @.PDCsCCsMonthly,
> RevenueByClient = @.RevenueByClient
> WHERE Customer_DashboardGraphs.Customer = @.CustomerID
> END
>
> My Table Schema:
> --------
> CREATE TABLE [dbo].[Customer_DashboardGraphs](
> [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.UpdateParameters("Budget").DefaultValue = intBudget
> Line 54:
> Line 55: ds_dashboard.Update()
> Line 56: End If
> Line 57: Next
>
> Source File:
> Y:\inetpub\wwwroot\apex\webapps\dashboard\dashboar d\index.aspx.vb Line: 55
>
> Stack Trace:
> ------
> [FormatException: String was not recognized as a valid Boolean.]
> System.Boolean.Parse(String value) +2709172
> System.String.System.IConvertible.ToBoolean(IForma tProvider provider) +12
> System.Convert.ChangeType(Object value, TypeCode typeCode,
> IFormatProvider provider) +98
> System.Web.UI.WebControls.Parameter.GetValue(Objec t value, String
> defaultValue, TypeCode type, Boolean convertEmptyStringToNull, Boolean
> ignoreNullableTypeChanges) +257
> System.Web.UI.WebControls.Parameter.get_ParameterV alue() +91
> System.Web.UI.WebControls.ParameterCollection.GetV alues(HttpContext
> context, Control control) +282
> System.Web.UI.WebControls.SqlDataSourceView.Initia lizeParameters(DbCommand
> command, ParameterCollection parameters, IDictionary exclusionList) +344
> System.Web.UI.WebControls.SqlDataSourceView.Execut eUpdate(IDictionary
> keys, IDictionary values, IDictionary oldValues) +449
> System.Web.UI.WebControls.SqlDataSourceView.Update (IDictionary keys,
> IDictionary values, IDictionary oldValues) +37
> System.Web.UI.WebControls.SqlDataSource.Update() +42
> dashboard._Default.UpdateCustomer_DashboardGraphs( Object sender,
> EventArgs e) in
> Y:\inetpub\wwwroot\sss\webapps\dashboard\dashboard \index.aspx.vb:55
> System.Web.UI.WebControls.Button.OnClick(EventArgs e) +96
> System.Web.UI.WebControls.Button.RaisePostBackEven t(String eventArgument)
> +116
> System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +31
> System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
> sourceControl, String eventArgument) +32
> System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +72
> System.Web.UI.Page.ProcessRequestMain(Boolean
> includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3837
>
> --
> dba123
>
> "Karl Seguin [MVP]" wrote:
> > which line is the error on?
> > Karl
> > --
> > http://www.openmymind.net/
> > "dba123" <dba123@.discussions.microsoft.com> wrote in message
> > news:0FCAE9F2-E68A-4794-9A68-BAF5877BA533@.microsoft.com...
> > > Why am I getting this error for Budget?
> > > > Error: An exception of type 'System.FormatException' occurred in
> > > mscorlib.dll but was not handled in user code
> > > > Additional information: String was not recognized as a valid Boolean.
> > > > > Public Sub UpdateCustomer_DashboardGraphs(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("lblCustomerID"), Label).Text.Trim()
> > > > '//--Textboxes
> > > Dim intBudget As Integer
> > > Try
> > > intBudget = CType(CType(gvr.FindControl("txtBudget"),
> > > TextBox).Text.Trim(), Int32)
> > > Catch
> > > intBudget = CType(0, Int32)
> > > End Try
> > > > '//--Checkboxes
> > > Dim intCurrentMonthCollections As Boolean =
> > > CType(gvr.FindControl("chbx_CurrentMonthCollections"), CheckBox).Checked
> > > Dim intRevenueByMonth As Boolean =
> > > CType(gvr.FindControl("chbx_RevenueByMonth"), CheckBox).Checked
> > > Dim intPDCsCCsMonthly As Boolean =
> > > CType(gvr.FindControl("chbx_PDCsCCsMonthly"), CheckBox).Checked
> > > Dim intRevenueByClient As Boolean =
> > > CType(gvr.FindControl("chbx_RevenueByClient"), CheckBox).Checked
> > > > '//--Assign UpdateParameters
> > > If intCurrentMonthCollections = True Then
> > > > ds_dashboard.UpdateParameters("CurrentMonthCollections").DefaultValue = 1
> > > Else
> > > > ds_dashboard.UpdateParameters("CurrentMonthCollections").DefaultValue = 0
> > > End If
> > > ...
> > > > ds_dashboard.UpdateParameters("Budget").DefaultValue =
> > > intBudget
> > > > ds_dashboard.Update()
> > > End If
> > > Next
> > > End Sub
> > > --
> > > dba123
Why don't you just set it to true/false instead of "true"/"fale"

ds_dashboard.UpdateParameters("CurrentMonthCollections").DefaultValue =
intCurrentMonthCollections

and why is that var prefixed with "int" if it's a bool? Prefixing isn't
really used much anymore anyways..

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/

"dba123" <dba123@.discussions.microsoft.com> wrote in message
news:460D12E2-2F3F-446F-BBA3-CA80CDAE09F1@.microsoft.com...
> 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.UpdateParameters("CurrentMonthCollections").DefaultValue = 1
> Else
> ds_dashboard.UpdateParameters("CurrentMonthCollections").DefaultValue = 0
> End If
> to
> If intCurrentMonthCollections = True Then
> ds_dashboard.UpdateParameters("CurrentMonthCollections").DefaultValue =
> "true"
> Else
> ds_dashboard.UpdateParameters("CurrentMonthCollections").DefaultValue =
> "false"
> End If
> The error goes away but it's still not updating those bit fields in my
> table
>
> --
> dba123
>
> "dba123" wrote:
>> 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:DashboardConn %>"
>> SelectCommand="aspx_Get_Customer_DashboardGraphs"
>> SelectCommandType="StoredProcedure"
>> UpdateCommand="aspx_Update_Customer_DashboardGraphs"
>> UpdateCommandType="StoredProcedure"
>> >
>> <UpdateParameters>
>> <asp:Parameter Name="CustomerID" Type="Int32" />
>> <asp:Parameter Name="Budget" Type="Int32" />
>> <asp:Parameter Name="CurrentMonthCollections"
>> 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"></HeaderStyle>
>> <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"></HeaderStyle>
>> <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"></HeaderStyle>
>> <ItemTemplate>
>> <asp:checkbox runat="server"
>> Id="chbx_CurrentMonthCollections" />
>> </ItemTemplate>
>> </asp:TemplateField>
>> <asp:TemplateField HeaderText="Revenue By Month"
>> SortExpression="Name" ItemStyle-HorizontalAlign="Center">
>> <HeaderStyle HorizontalAlign="center"></HeaderStyle>
>> <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"></HeaderStyle>
>> <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"></HeaderStyle>
>> <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_Customer_DashboardGraphs]
>>
>> @.CustomerID bigint,
>> @.Budget int,
>> @.CurrentMonthCollections bit,
>> @.RevenueByMonth bit,
>> @.PDCsCCsMonthly bit,
>> @.RevenueByClient bit
>>
>> AS
>> BEGIN
>>
>> UPDATE dbo.Customer_DashboardGraphs
>> SET Budget = @.Budget,
>> CurrentMonthCollections = @.CurrentMonthCollections,
>> RevenueByMonth = @.RevenueByMonth,
>> PDCsCCsMonthly = @.PDCsCCsMonthly,
>> RevenueByClient = @.RevenueByClient
>> WHERE Customer_DashboardGraphs.Customer = @.CustomerID
>> END
>>
>>
>> My Table Schema:
>> --------
>>
>> CREATE TABLE [dbo].[Customer_DashboardGraphs](
>> [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.UpdateParameters("Budget").DefaultValue = intBudget
>> Line 54:
>> Line 55: ds_dashboard.Update()
>> Line 56: End If
>> Line 57: Next
>>
>>
>> Source File:
>> Y:\inetpub\wwwroot\apex\webapps\dashboard\dashboar d\index.aspx.vb
>> Line: 55
>>
>>
>> Stack Trace:
>> ------
>>
>> [FormatException: String was not recognized as a valid Boolean.]
>> System.Boolean.Parse(String value) +2709172
>> System.String.System.IConvertible.ToBoolean(IForma tProvider provider)
>> +12
>> System.Convert.ChangeType(Object value, TypeCode typeCode,
>> IFormatProvider provider) +98
>> System.Web.UI.WebControls.Parameter.GetValue(Objec t value, String
>> defaultValue, TypeCode type, Boolean convertEmptyStringToNull, Boolean
>> ignoreNullableTypeChanges) +257
>> System.Web.UI.WebControls.Parameter.get_ParameterV alue() +91
>> System.Web.UI.WebControls.ParameterCollection.GetV alues(HttpContext
>> context, Control control) +282
>>
>> System.Web.UI.WebControls.SqlDataSourceView.Initia lizeParameters(DbCommand
>> command, ParameterCollection parameters, IDictionary exclusionList) +344
>> System.Web.UI.WebControls.SqlDataSourceView.Execut eUpdate(IDictionary
>> keys, IDictionary values, IDictionary oldValues) +449
>> System.Web.UI.WebControls.SqlDataSourceView.Update (IDictionary keys,
>> IDictionary values, IDictionary oldValues) +37
>> System.Web.UI.WebControls.SqlDataSource.Update() +42
>> dashboard._Default.UpdateCustomer_DashboardGraphs( Object sender,
>> EventArgs e) in
>> Y:\inetpub\wwwroot\sss\webapps\dashboard\dashboard \index.aspx.vb:55
>> System.Web.UI.WebControls.Button.OnClick(EventArgs e) +96
>> System.Web.UI.WebControls.Button.RaisePostBackEven t(String
>> eventArgument)
>> +116
>>
>> System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
>> eventArgument) +31
>> System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
>> sourceControl, String eventArgument) +32
>> System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
>> +72
>> System.Web.UI.Page.ProcessRequestMain(Boolean
>> includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
>> +3837
>>
>>
>> --
>> dba123
>>
>>
>> "Karl Seguin [MVP]" wrote:
>>
>> > which line is the error on?
>>> > Karl
>>> > --
>> > http://www.openmymind.net/
>>>>> > "dba123" <dba123@.discussions.microsoft.com> wrote in message
>> > news:0FCAE9F2-E68A-4794-9A68-BAF5877BA533@.microsoft.com...
>> > > Why am I getting this error for Budget?
>> >> > > Error: An exception of type 'System.FormatException' occurred in
>> > > mscorlib.dll but was not handled in user code
>> >> > > Additional information: String was not recognized as a valid Boolean.
>> >> >> > > Public Sub UpdateCustomer_DashboardGraphs(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("lblCustomerID"), Label).Text.Trim()
>> >> > > '//--Textboxes
>> > > Dim intBudget As Integer
>> > > Try
>> > > intBudget =
>> > > CType(CType(gvr.FindControl("txtBudget"),
>> > > TextBox).Text.Trim(), Int32)
>> > > Catch
>> > > intBudget = CType(0, Int32)
>> > > End Try
>> >> > > '//--Checkboxes
>> > > Dim intCurrentMonthCollections As Boolean =
>> > > CType(gvr.FindControl("chbx_CurrentMonthCollections"),
>> > > CheckBox).Checked
>> > > Dim intRevenueByMonth As Boolean =
>> > > CType(gvr.FindControl("chbx_RevenueByMonth"), CheckBox).Checked
>> > > Dim intPDCsCCsMonthly As Boolean =
>> > > CType(gvr.FindControl("chbx_PDCsCCsMonthly"), CheckBox).Checked
>> > > Dim intRevenueByClient As Boolean =
>> > > CType(gvr.FindControl("chbx_RevenueByClient"), CheckBox).Checked
>> >> > > '//--Assign UpdateParameters
>> > > If intCurrentMonthCollections = True Then
>> >> > > ds_dashboard.UpdateParameters("CurrentMonthCollections").DefaultValue
>> > > = 1
>> > > Else
>> >> > > ds_dashboard.UpdateParameters("CurrentMonthCollections").DefaultValue
>> > > = 0
>> > > End If
>> > > ...
>> >> > > ds_dashboard.UpdateParameters("Budget").DefaultValue =
>> > > intBudget
>> >> > > ds_dashboard.Update()
>> > > End If
>> > > Next
>> > > End Sub
>> > > --
>> > > dba123
>>>
Looks like I was missing the checked attribute in my GridView checkboxes??

I changed them to this for example but got an error

<HeaderStyle HorizontalAlign="center"></HeaderStyle>
<ItemTemplate>
<asp:checkbox runat="server"
Id="chbx_CurrentMonthCollections" Checked='<%#
Bind("CurrentMonthCollections") %>'/>
</ItemTemplate>
</asp:TemplateField
Error: An exception of type 'System.InvalidCastException' occurred in
Microsoft.VisualBasic.dll but was not handled in user code

Additional information: Conversion from type 'DBNull' to type 'Boolean' is
not valid.
--
dba123

"dba123" wrote:

> Why am I getting this error for Budget?
> Error: An exception of type 'System.FormatException' occurred in
> mscorlib.dll but was not handled in user code
> Additional information: String was not recognized as a valid Boolean.
>
> Public Sub UpdateCustomer_DashboardGraphs(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("lblCustomerID"), Label).Text.Trim()
> '//--Textboxes
> Dim intBudget As Integer
> Try
> intBudget = CType(CType(gvr.FindControl("txtBudget"),
> TextBox).Text.Trim(), Int32)
> Catch
> intBudget = CType(0, Int32)
> End Try
> '//--Checkboxes
> Dim intCurrentMonthCollections As Boolean =
> CType(gvr.FindControl("chbx_CurrentMonthCollections"), CheckBox).Checked
> Dim intRevenueByMonth As Boolean =
> CType(gvr.FindControl("chbx_RevenueByMonth"), CheckBox).Checked
> Dim intPDCsCCsMonthly As Boolean =
> CType(gvr.FindControl("chbx_PDCsCCsMonthly"), CheckBox).Checked
> Dim intRevenueByClient As Boolean =
> CType(gvr.FindControl("chbx_RevenueByClient"), CheckBox).Checked
> '//--Assign UpdateParameters
> If intCurrentMonthCollections = True Then
> ds_dashboard.UpdateParameters("CurrentMonthCollections").DefaultValue = 1
> Else
> ds_dashboard.UpdateParameters("CurrentMonthCollections").DefaultValue = 0
> End If
> ...
> ds_dashboard.UpdateParameters("Budget").DefaultValue =
> intBudget
> ds_dashboard.Update()
> End If
> Next
> End Sub
> --
> dba123
I still think prefix is useful for readablility.

Anyway, I trued True and False instead of "True" and "False" it made no
diffrence. Check out my previous post.

--
dba123

"Karl Seguin [MVP]" wrote:

> Why don't you just set it to true/false instead of "true"/"fale"
> ds_dashboard.UpdateParameters("CurrentMonthCollections").DefaultValue =
> intCurrentMonthCollections
> and why is that var prefixed with "int" if it's a bool? Prefixing isn't
> really used much anymore anyways..
> Karl
> --
> http://www.openmymind.net/
> http://www.fuelindustries.com/
>
> "dba123" <dba123@.discussions.microsoft.com> wrote in message
> news:460D12E2-2F3F-446F-BBA3-CA80CDAE09F1@.microsoft.com...
> > 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.UpdateParameters("CurrentMonthCollections").DefaultValue = 1
> > Else
> > ds_dashboard.UpdateParameters("CurrentMonthCollections").DefaultValue = 0
> > End If
> > to
> > If intCurrentMonthCollections = True Then
> > ds_dashboard.UpdateParameters("CurrentMonthCollections").DefaultValue =
> > "true"
> > Else
> > ds_dashboard.UpdateParameters("CurrentMonthCollections").DefaultValue =
> > "false"
> > End If
> > The error goes away but it's still not updating those bit fields in my
> > table
> > --
> > dba123
> > "dba123" wrote:
> >> 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:DashboardConn %>"
> >> SelectCommand="aspx_Get_Customer_DashboardGraphs"
> >> SelectCommandType="StoredProcedure"
> >> UpdateCommand="aspx_Update_Customer_DashboardGraphs"
> >> UpdateCommandType="StoredProcedure"
> >> >
> >> <UpdateParameters>
> >> <asp:Parameter Name="CustomerID" Type="Int32" />
> >> <asp:Parameter Name="Budget" Type="Int32" />
> >> <asp:Parameter Name="CurrentMonthCollections"
> >> 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"></HeaderStyle>
> >> <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"></HeaderStyle>
> >> <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"></HeaderStyle>
> >> <ItemTemplate>
> >> <asp:checkbox runat="server"
> >> Id="chbx_CurrentMonthCollections" />
> >> </ItemTemplate>
> >> </asp:TemplateField>
> >> <asp:TemplateField HeaderText="Revenue By Month"
> >> SortExpression="Name" ItemStyle-HorizontalAlign="Center">
> >> <HeaderStyle HorizontalAlign="center"></HeaderStyle>
> >> <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"></HeaderStyle>
> >> <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"></HeaderStyle>
> >> <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_Customer_DashboardGraphs]
> >>
> >> @.CustomerID bigint,
> >> @.Budget int,
> >> @.CurrentMonthCollections bit,
> >> @.RevenueByMonth bit,
> >> @.PDCsCCsMonthly bit,
> >> @.RevenueByClient bit
> >>
> >> AS
> >> BEGIN
> >>
> >> UPDATE dbo.Customer_DashboardGraphs
> >> SET Budget = @.Budget,
> >> CurrentMonthCollections = @.CurrentMonthCollections,
> >> RevenueByMonth = @.RevenueByMonth,
> >> PDCsCCsMonthly = @.PDCsCCsMonthly,
> >> RevenueByClient = @.RevenueByClient
> >> WHERE Customer_DashboardGraphs.Customer = @.CustomerID
> >> END
> >>
> >>
> >> My Table Schema:
> >> --------
> >>
> >> CREATE TABLE [dbo].[Customer_DashboardGraphs](
> >> [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.UpdateParameters("Budget").DefaultValue = intBudget
> >> Line 54:
> >> Line 55: ds_dashboard.Update()
> >> Line 56: End If
> >> Line 57: Next
> >>
> >>
> >> Source File:
> >> Y:\inetpub\wwwroot\apex\webapps\dashboard\dashboar d\index.aspx.vb
> >> Line: 55
> >>
> >>
> >> Stack Trace:
> >> ------
> >>
> >> [FormatException: String was not recognized as a valid Boolean.]
> >> System.Boolean.Parse(String value) +2709172
> >> System.String.System.IConvertible.ToBoolean(IForma tProvider provider)
> >> +12
> >> System.Convert.ChangeType(Object value, TypeCode typeCode,
> >> IFormatProvider provider) +98
> >> System.Web.UI.WebControls.Parameter.GetValue(Objec t value, String
> >> defaultValue, TypeCode type, Boolean convertEmptyStringToNull, Boolean
> >> ignoreNullableTypeChanges) +257
> >> System.Web.UI.WebControls.Parameter.get_ParameterV alue() +91
> >> System.Web.UI.WebControls.ParameterCollection.GetV alues(HttpContext
> >> context, Control control) +282
> >>
> >> System.Web.UI.WebControls.SqlDataSourceView.Initia lizeParameters(DbCommand
> >> command, ParameterCollection parameters, IDictionary exclusionList) +344
> >> System.Web.UI.WebControls.SqlDataSourceView.Execut eUpdate(IDictionary
> >> keys, IDictionary values, IDictionary oldValues) +449
> >> System.Web.UI.WebControls.SqlDataSourceView.Update (IDictionary keys,
> >> IDictionary values, IDictionary oldValues) +37
> >> System.Web.UI.WebControls.SqlDataSource.Update() +42
> >> dashboard._Default.UpdateCustomer_DashboardGraphs( Object sender,
> >> EventArgs e) in
> >> Y:\inetpub\wwwroot\sss\webapps\dashboard\dashboard \index.aspx.vb:55
> >> System.Web.UI.WebControls.Button.OnClick(EventArgs e) +96
> >> System.Web.UI.WebControls.Button.RaisePostBackEven t(String
> >> eventArgument)
> >> +116
> >>
> >> System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
> >> eventArgument) +31
> >> System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
> >> sourceControl, String eventArgument) +32
> >> System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
> >> +72
> >> System.Web.UI.Page.ProcessRequestMain(Boolean
> >> includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
> >> +3837
> >>
> >>
> >> --
> >> dba123
> >>
> >>
> >> "Karl Seguin [MVP]" wrote:
> >>
> >> > which line is the error on?
> >> >> > Karl
> >> >> > --
> >> > http://www.openmymind.net/
> >> >> >> >> > "dba123" <dba123@.discussions.microsoft.com> wrote in message
> >> > news:0FCAE9F2-E68A-4794-9A68-BAF5877BA533@.microsoft.com...
> >> > > Why am I getting this error for Budget?
> >> > >> > > Error: An exception of type 'System.FormatException' occurred in
> >> > > mscorlib.dll but was not handled in user code
> >> > >> > > Additional information: String was not recognized as a valid Boolean.
> >> > >> > >> > > Public Sub UpdateCustomer_DashboardGraphs(ByVal sender As Object,
> >> > > ByVal
> >> > > e As System.EventArgs)
> >> > > For Each gvr As GridViewRow In gv_dashboard.Rows
The answer to your question is..because I haven't cleaned up my code, I'll do
that at the end and change the prefixes, right now I just want to get this
thing to work!

--
dba123

"Karl Seguin [MVP]" wrote:

> Why don't you just set it to true/false instead of "true"/"fale"
> ds_dashboard.UpdateParameters("CurrentMonthCollections").DefaultValue =
> intCurrentMonthCollections
> and why is that var prefixed with "int" if it's a bool? Prefixing isn't
> really used much anymore anyways..
> Karl
> --
> http://www.openmymind.net/
> http://www.fuelindustries.com/
>
> "dba123" <dba123@.discussions.microsoft.com> wrote in message
> news:460D12E2-2F3F-446F-BBA3-CA80CDAE09F1@.microsoft.com...
> > 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.UpdateParameters("CurrentMonthCollections").DefaultValue = 1
> > Else
> > ds_dashboard.UpdateParameters("CurrentMonthCollections").DefaultValue = 0
> > End If
> > to
> > If intCurrentMonthCollections = True Then
> > ds_dashboard.UpdateParameters("CurrentMonthCollections").DefaultValue =
> > "true"
> > Else
> > ds_dashboard.UpdateParameters("CurrentMonthCollections").DefaultValue =
> > "false"
> > End If
> > The error goes away but it's still not updating those bit fields in my
> > table
> > --
> > dba123
> > "dba123" wrote:
> >> 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:DashboardConn %>"
> >> SelectCommand="aspx_Get_Customer_DashboardGraphs"
> >> SelectCommandType="StoredProcedure"
> >> UpdateCommand="aspx_Update_Customer_DashboardGraphs"
> >> UpdateCommandType="StoredProcedure"
> >> >
> >> <UpdateParameters>
> >> <asp:Parameter Name="CustomerID" Type="Int32" />
> >> <asp:Parameter Name="Budget" Type="Int32" />
> >> <asp:Parameter Name="CurrentMonthCollections"
> >> 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"></HeaderStyle>
> >> <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"></HeaderStyle>
> >> <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"></HeaderStyle>
> >> <ItemTemplate>
> >> <asp:checkbox runat="server"
> >> Id="chbx_CurrentMonthCollections" />
> >> </ItemTemplate>
> >> </asp:TemplateField>
> >> <asp:TemplateField HeaderText="Revenue By Month"
> >> SortExpression="Name" ItemStyle-HorizontalAlign="Center">
> >> <HeaderStyle HorizontalAlign="center"></HeaderStyle>
> >> <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"></HeaderStyle>
> >> <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"></HeaderStyle>
> >> <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_Customer_DashboardGraphs]
> >>
> >> @.CustomerID bigint,
> >> @.Budget int,
> >> @.CurrentMonthCollections bit,
> >> @.RevenueByMonth bit,
> >> @.PDCsCCsMonthly bit,
> >> @.RevenueByClient bit
> >>
> >> AS
> >> BEGIN
> >>
> >> UPDATE dbo.Customer_DashboardGraphs
> >> SET Budget = @.Budget,
> >> CurrentMonthCollections = @.CurrentMonthCollections,
> >> RevenueByMonth = @.RevenueByMonth,
> >> PDCsCCsMonthly = @.PDCsCCsMonthly,
> >> RevenueByClient = @.RevenueByClient
> >> WHERE Customer_DashboardGraphs.Customer = @.CustomerID
> >> END
> >>
> >>
> >> My Table Schema:
> >> --------
> >>
> >> CREATE TABLE [dbo].[Customer_DashboardGraphs](
> >> [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.UpdateParameters("Budget").DefaultValue = intBudget
> >> Line 54:
> >> Line 55: ds_dashboard.Update()
> >> Line 56: End If
> >> Line 57: Next
> >>
> >>
> >> Source File:
> >> Y:\inetpub\wwwroot\apex\webapps\dashboard\dashboar d\index.aspx.vb
> >> Line: 55
> >>
> >>
> >> Stack Trace:
> >> ------
> >>
> >> [FormatException: String was not recognized as a valid Boolean.]
> >> System.Boolean.Parse(String value) +2709172
> >> System.String.System.IConvertible.ToBoolean(IForma tProvider provider)
> >> +12
> >> System.Convert.ChangeType(Object value, TypeCode typeCode,
> >> IFormatProvider provider) +98
> >> System.Web.UI.WebControls.Parameter.GetValue(Objec t value, String
> >> defaultValue, TypeCode type, Boolean convertEmptyStringToNull, Boolean
> >> ignoreNullableTypeChanges) +257
> >> System.Web.UI.WebControls.Parameter.get_ParameterV alue() +91
> >> System.Web.UI.WebControls.ParameterCollection.GetV alues(HttpContext
> >> context, Control control) +282
> >>
> >> System.Web.UI.WebControls.SqlDataSourceView.Initia lizeParameters(DbCommand
> >> command, ParameterCollection parameters, IDictionary exclusionList) +344
> >> System.Web.UI.WebControls.SqlDataSourceView.Execut eUpdate(IDictionary
> >> keys, IDictionary values, IDictionary oldValues) +449
> >> System.Web.UI.WebControls.SqlDataSourceView.Update (IDictionary keys,
> >> IDictionary values, IDictionary oldValues) +37
> >> System.Web.UI.WebControls.SqlDataSource.Update() +42
> >> dashboard._Default.UpdateCustomer_DashboardGraphs( Object sender,
> >> EventArgs e) in
> >> Y:\inetpub\wwwroot\sss\webapps\dashboard\dashboard \index.aspx.vb:55
> >> System.Web.UI.WebControls.Button.OnClick(EventArgs e) +96
> >> System.Web.UI.WebControls.Button.RaisePostBackEven t(String
> >> eventArgument)
> >> +116
> >>
> >> System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
> >> eventArgument) +31
> >> System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
> >> sourceControl, String eventArgument) +32
> >> System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
> >> +72
> >> System.Web.UI.Page.ProcessRequestMain(Boolean
> >> includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
> >> +3837
> >>
> >>
> >> --
> >> dba123
> >>
> >>
> >> "Karl Seguin [MVP]" wrote:
> >>
> >> > which line is the error on?
> >> >> > Karl
> >> >> > --
> >> > http://www.openmymind.net/
> >> >> >> >> > "dba123" <dba123@.discussions.microsoft.com> wrote in message
> >> > news:0FCAE9F2-E68A-4794-9A68-BAF5877BA533@.microsoft.com...
> >> > > Why am I getting this error for Budget?
> >> > >> > > Error: An exception of type 'System.FormatException' occurred in
> >> > > mscorlib.dll but was not handled in user code
> >> > >> > > Additional information: String was not recognized as a valid Boolean.
> >> > >> > >> > > Public Sub UpdateCustomer_DashboardGraphs(ByVal sender As Object,
> >> > > ByVal
> >> > > e As System.EventArgs)
> >> > > For Each gvr As GridViewRow In gv_dashboard.Rows
you need to check for null. Either don't allow null in that column and use
a default value, use select IsNull(CurrentMonthCollections, false) as
CurrentMonthCollections for selecting a default value, or check for null
before binding, you can do that inline via:

<%# ( Bind("CurrentMonthCollections") == DBNull.Value) ? false : true; %
Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/

"dba123" <dba123@.discussions.microsoft.com> wrote in message
news:575A281C-2B41-41BD-AC49-3F5A8F0A207B@.microsoft.com...
> Looks like I was missing the checked attribute in my GridView checkboxes??
> I changed them to this for example but got an error
> <HeaderStyle HorizontalAlign="center"></HeaderStyle>
> <ItemTemplate>
> <asp:checkbox runat="server"
> Id="chbx_CurrentMonthCollections" Checked='<%#
> Bind("CurrentMonthCollections") %>'/>
> </ItemTemplate>
> </asp:TemplateField>
> Error: An exception of type 'System.InvalidCastException' occurred in
> Microsoft.VisualBasic.dll but was not handled in user code
> Additional information: Conversion from type 'DBNull' to type 'Boolean' is
> not valid.
> --
> dba123
>
> "dba123" wrote:
>> Why am I getting this error for Budget?
>>
>> Error: An exception of type 'System.FormatException' occurred in
>> mscorlib.dll but was not handled in user code
>>
>> Additional information: String was not recognized as a valid Boolean.
>>
>>
>> Public Sub UpdateCustomer_DashboardGraphs(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("lblCustomerID"), Label).Text.Trim()
>>
>> '//--Textboxes
>> Dim intBudget As Integer
>> Try
>> intBudget = CType(CType(gvr.FindControl("txtBudget"),
>> TextBox).Text.Trim(), Int32)
>> Catch
>> intBudget = CType(0, Int32)
>> End Try
>>
>> '//--Checkboxes
>> Dim intCurrentMonthCollections As Boolean =
>> CType(gvr.FindControl("chbx_CurrentMonthCollections"), CheckBox).Checked
>> Dim intRevenueByMonth As Boolean =
>> CType(gvr.FindControl("chbx_RevenueByMonth"), CheckBox).Checked
>> Dim intPDCsCCsMonthly As Boolean =
>> CType(gvr.FindControl("chbx_PDCsCCsMonthly"), CheckBox).Checked
>> Dim intRevenueByClient As Boolean =
>> CType(gvr.FindControl("chbx_RevenueByClient"), CheckBox).Checked
>>
>> '//--Assign UpdateParameters
>> If intCurrentMonthCollections = True Then
>>
>> ds_dashboard.UpdateParameters("CurrentMonthCollections").DefaultValue = 1
>> Else
>>
>> ds_dashboard.UpdateParameters("CurrentMonthCollections").DefaultValue = 0
>> End If
>> ...
>>
>> ds_dashboard.UpdateParameters("Budget").DefaultValue =
>> intBudget
>>
>> ds_dashboard.Update()
>> End If
>> Next
>> End Sub
>> --
>> dba123
Thanks you are correct. What I did was changed my SelectCommand stored proc
to replace the nulls with 0 instead.

see here for my latest code. Now no errors but also no updates happening on
the DB side:

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:DashboardConn %>"
SelectCommand="aspx_Get_Customer_DashboardGraphs"
SelectCommandType="StoredProcedure"
UpdateCommand="aspx_Update_Customer_DashboardGraphs"
UpdateCommandType="StoredProcedure"
<UpdateParameters>
<asp:Parameter Name="CustomerID" Type="Int32" />
<asp:Parameter Name="Budget" Type="Int32" />
<asp:Parameter Name="CurrentMonthCollections"
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"></HeaderStyle>
<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"></HeaderStyle>
<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"></HeaderStyle>
<ItemTemplate>
<asp:checkbox runat="server"
Id="chbx_CurrentMonthCollections" Checked='<%#
Bind("CurrentMonthCollections") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Revenue By Month"
SortExpression="Name" ItemStyle-HorizontalAlign="Center">
<HeaderStyle HorizontalAlign="center"></HeaderStyle>
<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"></HeaderStyle>
<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"></HeaderStyle>
<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 Select Command

ALTER PROCEDURE [dbo].[aspx_Get_Customer_DashboardGraphs]

AS
BEGIN

SELECTCustomer,
ISNULL(Budget, 0) as Budget,
ISNULL(CurrentMonthCollections, 0) as CurrentMonthCollections,
ISNULL(RevenueByMonth, 0)as RevenueByMonth,
ISNULL(PDCsCCsMonthly, 0) as PDCsCCsMonthly,
ISNULL(RevenueByClient, 0) as RevenueByClient

FROM v_Get_Customer_DashboardGraphs_Data
ORDER BY Customer ASC
END

Stored proc behind the Update Command:

ALTER PROCEDURE [dbo].[aspx_Update_Customer_DashboardGraphs]

@.CustomerIDbigint,
@.Budgetbigint,
@.CurrentMonthCollectionsbit,
@.RevenueByMonthbit,
@.PDCsCCsMonthlybit,
@.RevenueByClientbit

AS
BEGIN

UPDATE dbo.Customer_DashboardGraphs
SET Budget = @.Budget,
CurrentMonthCollections = @.CurrentMonthCollections,
RevenueByMonth = @.RevenueByMonth,
PDCsCCsMonthly = @.PDCsCCsMonthly,
RevenueByClient = @.RevenueByClient
WHERE Customer_DashboardGraphs.Customer = @.CustomerID
END

------------ Code Behind
-------------------

Public Sub UpdateCustomer_DashboardGraphs(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("lblCustomerID"), Label).Text.Trim()

'//--Textboxes
Dim intBudget As Integer
Try
intBudget = CType(CType(gvr.FindControl("txtBudget"),
TextBox).Text.Trim(), Int32)
Catch
intBudget = 0
End Try

'//--Checkboxes
Dim bolCurrentMonthCollections As Boolean =
CType(gvr.FindControl("chbx_CurrentMonthCollections"), CheckBox).Checked
Dim bolRevenueByMonth As Boolean =
CType(gvr.FindControl("chbx_RevenueByMonth"), CheckBox).Checked
Dim bolPDCsCCsMonthly As Boolean =
CType(gvr.FindControl("chbx_PDCsCCsMonthly"), CheckBox).Checked
Dim bolRevenueByClient As Boolean =
CType(gvr.FindControl("chbx_RevenueByClient"), CheckBox).Checked

'//--Assign UpdateParameters
If bolCurrentMonthCollections = True Then

ds_dashboard.UpdateParameters("CurrentMonthCollections").DefaultValue = True
Else

ds_dashboard.UpdateParameters("CurrentMonthCollections").DefaultValue = False
End If
If bolRevenueByMonth = True Then

ds_dashboard.UpdateParameters("RevenueByMonth").DefaultValue = True
Else

ds_dashboard.UpdateParameters("RevenueByMonth").DefaultValue = False
End If
If bolPDCsCCsMonthly = True Then

ds_dashboard.UpdateParameters("PDCsCCsMonthly").DefaultValue = True
Else

ds_dashboard.UpdateParameters("PDCsCCsMonthly").DefaultValue = False
End If
If bolRevenueByClient = True Then

ds_dashboard.UpdateParameters("RevenueByClient").DefaultValue = True
Else

ds_dashboard.UpdateParameters("RevenueByClient").DefaultValue = False
End If

ds_dashboard.UpdateParameters("Budget").DefaultValue =
intBudget

ds_dashboard.Update()
End If
Next
End Sub

--
dba123

"Karl Seguin [MVP]" wrote:

> you need to check for null. Either don't allow null in that column and use
> a default value, use select IsNull(CurrentMonthCollections, false) as
> CurrentMonthCollections for selecting a default value, or check for null
> before binding, you can do that inline via:
> <%# ( Bind("CurrentMonthCollections") == DBNull.Value) ? false : true; %>
> Karl
> --
> http://www.openmymind.net/
> http://www.fuelindustries.com/
>
> "dba123" <dba123@.discussions.microsoft.com> wrote in message
> news:575A281C-2B41-41BD-AC49-3F5A8F0A207B@.microsoft.com...
> > Looks like I was missing the checked attribute in my GridView checkboxes??
> > I changed them to this for example but got an error
> > <HeaderStyle HorizontalAlign="center"></HeaderStyle>
> > <ItemTemplate>
> > <asp:checkbox runat="server"
> > Id="chbx_CurrentMonthCollections" Checked='<%#
> > Bind("CurrentMonthCollections") %>'/>
> > </ItemTemplate>
> > </asp:TemplateField>
> > Error: An exception of type 'System.InvalidCastException' occurred in
> > Microsoft.VisualBasic.dll but was not handled in user code
> > Additional information: Conversion from type 'DBNull' to type 'Boolean' is
> > not valid.
> > --
> > dba123
> > "dba123" wrote:
> >> Why am I getting this error for Budget?
> >>
> >> Error: An exception of type 'System.FormatException' occurred in
> >> mscorlib.dll but was not handled in user code
> >>
> >> Additional information: String was not recognized as a valid Boolean.
> >>
> >>
> >> Public Sub UpdateCustomer_DashboardGraphs(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("lblCustomerID"), Label).Text.Trim()
> >>
> >> '//--Textboxes
> >> Dim intBudget As Integer
> >> Try
> >> intBudget = CType(CType(gvr.FindControl("txtBudget"),
> >> TextBox).Text.Trim(), Int32)
> >> Catch
> >> intBudget = CType(0, Int32)
> >> End Try
> >>
> >> '//--Checkboxes
> >> Dim intCurrentMonthCollections As Boolean =
> >> CType(gvr.FindControl("chbx_CurrentMonthCollections"), CheckBox).Checked
> >> Dim intRevenueByMonth As Boolean =
> >> CType(gvr.FindControl("chbx_RevenueByMonth"), CheckBox).Checked
> >> Dim intPDCsCCsMonthly As Boolean =
> >> CType(gvr.FindControl("chbx_PDCsCCsMonthly"), CheckBox).Checked
> >> Dim intRevenueByClient As Boolean =
> >> CType(gvr.FindControl("chbx_RevenueByClient"), CheckBox).Checked
> >>
> >> '//--Assign UpdateParameters
> >> If intCurrentMonthCollections = True Then
> >>
> >> ds_dashboard.UpdateParameters("CurrentMonthCollections").DefaultValue = 1
> >> Else
> >>
> >> ds_dashboard.UpdateParameters("CurrentMonthCollections").DefaultValue = 0
> >> End If
> >> ...
> >>
> >> ds_dashboard.UpdateParameters("Budget").DefaultValue =
> >> intBudget
> >>
> >> ds_dashboard.Update()
> >> End If
> >> Next
> >> End Sub
> >> --
> >> dba123
>
'<%# ( Bind("RevenueByClient") == DBNull.Value) ? false : true; %>'

I've never used that syntax before, didn't even know you could do that so
thatnks, but getting error with your suggestion:

Line 63: <HeaderStyle HorizontalAlign="center"></HeaderStyle>
Line 64: <ItemTemplate>
Line 65: <asp:checkbox runat="server"
Id="chbx_CurrentMonthCollections" Checked='<%# (
Bind("CurrentMonthCollections") == DBNull.Value) ? false : true; %>'/>
Line 66: </ItemTemplate>
Line 67: </asp:TemplateField
--
dba123

"Karl Seguin [MVP]" wrote:

> you need to check for null. Either don't allow null in that column and use
> a default value, use select IsNull(CurrentMonthCollections, false) as
> CurrentMonthCollections for selecting a default value, or check for null
> before binding, you can do that inline via:
> <%# ( Bind("CurrentMonthCollections") == DBNull.Value) ? false : true; %>
> Karl
> --
> http://www.openmymind.net/
> http://www.fuelindustries.com/
>
> "dba123" <dba123@.discussions.microsoft.com> wrote in message
> news:575A281C-2B41-41BD-AC49-3F5A8F0A207B@.microsoft.com...
> > Looks like I was missing the checked attribute in my GridView checkboxes??
> > I changed them to this for example but got an error
> > <HeaderStyle HorizontalAlign="center"></HeaderStyle>
> > <ItemTemplate>
> > <asp:checkbox runat="server"
> > Id="chbx_CurrentMonthCollections" Checked='<%#
> > Bind("CurrentMonthCollections") %>'/>
> > </ItemTemplate>
> > </asp:TemplateField>
> > Error: An exception of type 'System.InvalidCastException' occurred in
> > Microsoft.VisualBasic.dll but was not handled in user code
> > Additional information: Conversion from type 'DBNull' to type 'Boolean' is
> > not valid.
> > --
> > dba123
> > "dba123" wrote:
> >> Why am I getting this error for Budget?
> >>
> >> Error: An exception of type 'System.FormatException' occurred in
> >> mscorlib.dll but was not handled in user code
> >>
> >> Additional information: String was not recognized as a valid Boolean.
> >>
> >>
> >> Public Sub UpdateCustomer_DashboardGraphs(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("lblCustomerID"), Label).Text.Trim()
> >>
> >> '//--Textboxes
> >> Dim intBudget As Integer
> >> Try
> >> intBudget = CType(CType(gvr.FindControl("txtBudget"),
> >> TextBox).Text.Trim(), Int32)
> >> Catch
> >> intBudget = CType(0, Int32)
> >> End Try
> >>
> >> '//--Checkboxes
> >> Dim intCurrentMonthCollections As Boolean =
> >> CType(gvr.FindControl("chbx_CurrentMonthCollections"), CheckBox).Checked
> >> Dim intRevenueByMonth As Boolean =
> >> CType(gvr.FindControl("chbx_RevenueByMonth"), CheckBox).Checked
> >> Dim intPDCsCCsMonthly As Boolean =
> >> CType(gvr.FindControl("chbx_PDCsCCsMonthly"), CheckBox).Checked
> >> Dim intRevenueByClient As Boolean =
> >> CType(gvr.FindControl("chbx_RevenueByClient"), CheckBox).Checked
> >>
> >> '//--Assign UpdateParameters
> >> If intCurrentMonthCollections = True Then
> >>
> >> ds_dashboard.UpdateParameters("CurrentMonthCollections").DefaultValue = 1
> >> Else
> >>
> >> ds_dashboard.UpdateParameters("CurrentMonthCollections").DefaultValue = 0
> >> End If
> >> ...
> >>
> >> ds_dashboard.UpdateParameters("Budget").DefaultValue =
> >> intBudget
> >>
> >> ds_dashboard.Update()
> >> End If
> >> Next
> >> End Sub
> >> --
> >> dba123
>