Showing posts with label string. Show all posts
Showing posts with label string. Show all posts

Saturday, March 31, 2012

trim and pure apparently whitespace strings

has anyone encountered an apparently pure whitespace string (debug mode
mouse-over) that when TRIM'd does not result in a null-string ?

how to determine any special characters that may be present in the string ?trimming a string with just spaces will return an empty string ("") not a
null string (null)...

The easiest way to evaluate the string would be to write it to disk. Create
a file and write the string out, then analyse the file in a hex editor to
check for excape characters.

"John A Grandy" <johnagrandy-at-yahoo-dot-com> wrote in message
news:eFtfjQG0EHA.1264@.TK2MSFTNGP12.phx.gbl...
> has anyone encountered an apparently pure whitespace string (debug mode
> mouse-over) that when TRIM'd does not result in a null-string ?
> how to determine any special characters that may be present in the string
> ?
i was using "null-string" in the traditional sense of a reference to a
String datatype object that consists of 0 characters -- not a
"null-reference" (a reference to Nothing)

actually, i found this very useful function for discovering hidden
characters in a string:

Uri.HexEscape()

"Dan Bass" <danielbass [at] postmaster [dot] co [dot] uk> wrote in message
news:OAfw44H0EHA.2600@.TK2MSFTNGP09.phx.gbl...
> trimming a string with just spaces will return an empty string ("") not a
> null string (null)...
> The easiest way to evaluate the string would be to write it to disk.
Create
> a file and write the string out, then analyse the file in a hex editor to
> check for excape characters.
>
> "John A Grandy" <johnagrandy-at-yahoo-dot-com> wrote in message
> news:eFtfjQG0EHA.1264@.TK2MSFTNGP12.phx.gbl...
> > has anyone encountered an apparently pure whitespace string (debug mode
> > mouse-over) that when TRIM'd does not result in a null-string ?
> > how to determine any special characters that may be present in the
string
> > ?

trim and pure apparently whitespace strings

has anyone encountered an apparently pure whitespace string (debug mode
mouse-over) that when TRIM'd does not result in a null-string ?
how to determine any special characters that may be present in the string ?trimming a string with just spaces will return an empty string ("") not a
null string (null)...
The easiest way to evaluate the string would be to write it to disk. Create
a file and write the string out, then analyse the file in a hex editor to
check for excape characters.
"John A Grandy" <johnagrandy-at-yahoo-dot-com> wrote in message
news:eFtfjQG0EHA.1264@.TK2MSFTNGP12.phx.gbl...
> has anyone encountered an apparently pure whitespace string (debug mode
> mouse-over) that when TRIM'd does not result in a null-string ?
> how to determine any special characters that may be present in the string
> ?
>
i was using "null-string" in the traditional sense of a reference to a
String datatype object that consists of 0 characters -- not a
"null-reference" (a reference to Nothing)
actually, i found this very useful function for discovering hidden
characters in a string:
Uri.HexEscape()
"Dan Bass" <danielbass [at] postmaster [dot] co [dot] uk> wrote in message
news:OAfw44H0EHA.2600@.TK2MSFTNGP09.phx.gbl...
> trimming a string with just spaces will return an empty string ("") not a
> null string (null)...
> The easiest way to evaluate the string would be to write it to disk.
Create
> a file and write the string out, then analyse the file in a hex editor to
> check for excape characters.
>
> "John A Grandy" <johnagrandy-at-yahoo-dot-com> wrote in message
> news:eFtfjQG0EHA.1264@.TK2MSFTNGP12.phx.gbl...
string
>

trim left 5 character.

Hi guys

I am using vb.net

I have this "12.95-ups ground" string and I need to get the string after the dash

could you send me your suggestions please.

thanks

Cemal

Hi, try this:

Dim myStrAs String ="12.95-ups ground"Dim myTrimAs String = Mid(myStr, InStr(myStr,"-") + 1)

try something like below

index=yourStringVariable.IndexOf(".");
then
YourString.Substring( check what parameter this function requires)


string _strTest = "12.95-ups ground";
Response.Write ( _strTest.Substring ( 6 ) ) ;

Thanks

-Mark post(s) as "Answer" that helped you


dim str as string

str="12.95-ups ground"

dim newVal as string

newVal=str.substring(str.indexof("-")+1)

response.write(newVal)

Trim String

Hi

I want to trim the end of a string placed on my page.

I want to make it so that even if the text is 100 char long it will only display the first 15 characters.

Is this correct, i cant seem to make it work.

Regards
Ant

<%#Container.DataItem("OutboundCarrierName").ToString.Trim("15") %>

use Substring function in place of this:

<%#Container.DataItem("OutboundCarrierName").ToString().Substring(0,15) %>

thanks


Perfect, that works.

Trim string to fit in fixed width Table Cell [Edited by Adec, moderator]

I have the following BIG problemSmile [:)]
The column of datagrid is bind to a database field.
If lenght of string is bigger than the column width i want to trim the string.
No metter if the trimmed word has sense.
I would like to know if anyone knows if there is a way to calculate
string width in pixel in connection to font size used in that particular cell.
You can check the string size and do what you need to with it in your DataGridItemCreated event handler.
that's ok for the position where check, but the problem is how measure the width in pixel of the string:-)
Your getting confused, and making this to complicated. You dont measure strings in pixels, you measure strings in Charatchers, figure out how many charatchers will fit in the column of your datagrid, and trim the string to that amount of chars, I would recomend trimming it to 3 less chars than will fit and appending on a ... so that users know it's been trimmed.
Remember, capital letters take up more space than lower case ones, and different ascii chars can take up a space and a half in some cases purley literally speaking, like the @. symbol.

I would suggest you use sql to get the substring - select substring(myfield, 1, 10) as myfield from my table. This gets the first 10 characters. To add the "..." then select substring(myfield, 1, 7)+'...' as myfield from my table


It is ok, i will follow your indication. But still look for a method like TextWidth("...") to use in application.
Thanks. Best Regards

Trim the first character

How do i trim the first character.
I have string $22.22 and i want to be left with 22.22
I cant use subString(int,int) because i dont know the length of the stringYou can determine the length using the .Length property. So you can trim in C# like this:
string s = "$22.22";
s = s.Substring(1, s.Length - 1);
's' will now be "22.22"
There is also an overloaded substring method that only requires the starting character position:

strimmed=s.substring(1)

Trim URL String

I am trying to populate selected values from a drop-down list into URL params. I have the below code, which is supposed to remove the trailing comma from the end of the URL, but it does not seem to be working. Does anyone see anything obviously incorrect?

Thanks in advance.
----------

if (lbxWFTemplate.Visible ==true)

{

strURL +="WFTemplate=";

foreach (ListItem liWFTemplatein lbxWFTemplate.Items)

{

if (liWFTemplate.Selected)

{

strURL += liWFTemplate.Value.ToString() +",";

}

}

strURL.TrimEnd(",".ToCharArray());

I actually figured this out right after I posted. Trimend() returns a string, so the following was changed, and the code works as expected now:
strURL = strURL.TrimEnd(",".ToCharArray());

Trim whitespace (start and end) of string

Just wondering how you can trim the whitespace of a string for the start and end of it.


e.g. " My String "

Thanks!

nothing more then string.trim(); put the string value in a string variable.

greets,

Erdem


Here are the methods available to you

publicstring Trim(paramschar[] trimChars);

publicstring Trim();

publicstring TrimStart(paramschar[] trimChars);

publicstring TrimEnd(paramschar[] trimChars);


Hi,

try this

String myString = " My String ";

myString.Trim(' ');

Regards

Trimming Blank Spaces in String

You can use the VB.NET function RTRIM.

--
I hope this helps,
Steve C. Orr, MCSD
http://Steve.Orr.net

"Temp" <tempmail@dotnet.itags.org.temp.com> wrote in message
news:bh1eg5$o2h@dotnet.itags.org.library2.airnews.net...
> I am trying to remove the blank spaces at the end of a string with the
> .Trim() function. Unfortunately, this removes ALL spaces, not just the
ones
> at the end. I need to preserve the spacing inside the string.
> Does anyone know how I can do this?
> Thanks,
> Ron
> --
> _____________________________
> Ron Rodenberg
> Lead Software Engineer
> Razorvision Technology, Inc.
> (214) 207-1688Do you know of a C# equivalent?

--
_____________________________
Ron Rodenberg
Lead Software Engineer
Razorvision Technology, Inc.
(214) 207-1688
"Steve C. Orr, MCSD" <Steve@.Orr.net> wrote in message
news:%23Qab%23wgXDHA.2392@.TK2MSFTNGP10.phx.gbl...
> You can use the VB.NET function RTRIM.
> --
> I hope this helps,
> Steve C. Orr, MCSD
> http://Steve.Orr.net
>
> "Temp" <tempmail@.temp.com> wrote in message
> news:bh1eg5$o2h@.library2.airnews.net...
> > I am trying to remove the blank spaces at the end of a string with the
> > .Trim() function. Unfortunately, this removes ALL spaces, not just the
> ones
> > at the end. I need to preserve the spacing inside the string.
> > Does anyone know how I can do this?
> > Thanks,
> > Ron
> > --
> > _____________________________
> > Ron Rodenberg
> > Lead Software Engineer
> > Razorvision Technology, Inc.
> > (214) 207-1688

Trimming a string to remove special & non-numeric characters

the string format is "XXXXXX-06-X-1234". how can i trim it so that it removes all the dashes and non-numeric characters? the result after such a trim would be "061234"

thanks in advance.

Create a function that removes any characters you don't want. In this case, it's pretty easy:

Function ParseDigits(ByVal strRawValue asString)As String Dim strDigitsAs String =""If strRawValue =Nothing Then Return strDigitsFor Each cAs Char In strRawValue.ToCharArray()If c.IsDigitThen strDigits &= cEnd If Next c' return the number string, or "" if no numbers were in the string.Return strDigitsEnd Function

You can always iterate through each character and build a new string (Use the StringBuilder class). You could also try using RegEx.Replace method to replace all non-numeric characters with an empty string. I don't know which method would perform faster, if I had to guess, I'd say the manual iteration approach.

Does anyone know an easier way to do this?


quickest way to do this (and best performance is with a Regex:

C#:

string initialString ="XXXXXX-06-X-1234";System.Text.RegularExpressions.Regex nonNumericCharacters =new System.Text.RegularExpressions.Regex(@."\D");string numericOnlyString = nonNumericCharacters.Replace(initialString, String.Empty);

VB:

Dim initialString asString ="XXXXXX-06-X-1234"Dim nonNumericCharactersAs New System.Text.RegularExpressions.Regex(@."\D")Dim numericOnlyStringAs String = nonNumericCharacters.Replace(initialString,String.Empty)

Enjoy.


I think you did that backwards. You're having him match all numbers and replace them with an empty string. He WANTS numbers!

C#:

string initialString ="XXXXXX-06-X-1234";System.Text.RegularExpressions.Regex nonNumericCharacters =new System.Text.RegularExpressions.Regex(@."[^0-9]");string numericOnlyString = nonNumericCharacters.Replace(initialString, String.Empty);

VB:

Dim initialString asString ="XXXXXX-06-X-1234"Dim nonNumericCharactersAs New System.Text.RegularExpressions.Regex("[^0-9]")Dim numericOnlyStringAs String = nonNumericCharacters.Replace(initialString,String.Empty)

the "d" is capitalised:

/d = [0-9]

and

/D = [^0-9]

either way, you can use /D or [^0-9]


bipro/ds2goat

thanks for the help! that function works great. one more question though. sometimes the first set of characters (XXXXXX-) can have a number. is there anyway to totally ignore those first 6 characters, then trim the remaining characters using the function above?

example: "221300-06-D-1234" would come out as "061234"

thanks again for the help


bipro/ps2goat

thanks for the help! that function works great. one more question though. sometimes the first set of characters (XXXXXX-) can have a number. is there anyway to totally ignore those first 6 characters, then trim the remaining characters using the function above?

example: "221300-06-D-1234" would come out as "061234"

thanks again for the help


Is this a consistent thing? I.e., do all of the strings you are working with have those six characters you want to ignore? What kind of consistent pattern is there in the data?

yes, it is a consistent pattern (AAANNN-NN-A-NNNN), where "A" is alpha & "N" is numeric. i want to always ignore the first 6 characters, whether they be alpha or numeric.

thanks again.


You can get rid of the first 6 characters by

string _test = "AAANNN-NN-A-NNNN";
_test = _test.Replace(_test.Substring(0,6), string.Empty);

Now apply the above regular expression on the _test;

Thanks


works perfectly! here's my entire function:

Dim testAs String ="SPM300-06-D-1234"test = test.Replace(test.Substring(0, 6),String.Empty)Dim nonNumericCharactersAs New System.Text.RegularExpressions.Regex("\D")Dim numericOnlyStringAs String = nonNumericCharacters.Replace(test,String.Empty)Response.Write(numericOnlyString)
thanks again for all the help. i really appreciate it.
test = test.Replace(test.Substring(0, 6),String.Empty)
It seems to me that it makes more sense to do one operation than 2. e_screw told you to do

but it would read better if you did this instead:

test = test.Substring(6)
This will return all characters after index 6 (or the seventh character, since you don't need the first hypen either). Good programming is being lazy, and being lazy means writing less code to do what you want (less = more efficient). =)

Wednesday, March 28, 2012

Trouble converting object to a string using format

Hi all,

I have an object (ie: type Object) which contains a date string like this: 28/04/2004 02:32:52 PM. (This object comes from a legacy COM dll that we use against our database so I can't change this type.)

I want to convert this Object's string to a date in a date format such as "yyyy-MM-dd" which is stored in another string (we get this from the globalisation settings as follows):

_dateFormat = new System.Globalization.CultureInfo(Request.ServerVariables["HTTP_ACCEPT_LANGUAGE"], true).DateTimeFormat.ShortDatePattern.ToString();

So, taking my object with the long date string (remember, it is not a DateTime object) I want to convert it to another string using the format above... so I'd get a string containing "2004-04-28".

Anyone know how I can do this... it should be easy but I can't seem to get it to work.

TIA for any help...

MikeHello,
what don't u use something like this:

( (DateTime)urObject).ToShortDateString();

try it and tell me what happens.
Thanks Haidar... don't why I didn't get that first time around!

Cheers,

Mike
Glad i was able to help you out my friend.

Good Luck.

Monday, March 26, 2012

Trouble formating string for label.

Hey everyone!

Weird situation here. I have this label:

<asp:label id="lblDepositDue" runat="server" />

I am trying to set it's value with this statement:
lblDepositDue.Text = "Deposit Due Upon Booking: " & String.Format("{0:c}", intDepositDue.ToString)

Simple right? But the output still comes out looking like this:

Deposit Due Upon Booking: 4999

...instead of like this which SHOULD be the output:

Deposit Due Upon Booking: $4,999.00

What is going wrong?

Thanks.....MikeHow about something like this:


lblProductCost.Text = Format(intProductCost, "#,##0.00")

Hey...

When I try:

lblDepositDue.Text = "Deposit Due Upon Booking: " & Format(intTotalTourCost.ToString, "#,##0.00")

It comes out like this:

Deposit Due Upon Booking: #,##0.00

:-/
Hi,

as was said, do not call ToString for the integer argument passed to the Format function (it was same problem with your original code):

Instead of:


Format(intTotalTourCost.ToString, "#,##0.00")

use

Format(intTotalTourCost, "#,##0.00")

In your original code following would have worked:


String.Format("{0:c}",intDepositDue)

Note that ToString is not called for the argument. String formatting is formatting from another data type type to string. Capability to format comes when argument is typed, If you pass it as string with ToString method, it's original type is not known (strictly speaking is, it is string as well and goes through formatting as is) and it can't be formatted.
Teemu,

Thank you very much for the clarification. I was under the (incorrect) assumption that String.Format required that the value passed to is was in string format already. I wasn't aware of any conversion to string simply by formatting.

Thanks again!

Mike

Saturday, March 24, 2012

Trouble saving html in a string variable

I'm trying to allow a user to enter html text into a textBox (FreeTextBox) but am getting an error upon submitting:

A potentially dangerous Request.Form value was detected from the client (noteTextBox="<H2><FONT size=6>asd...").
Description:Request Validation has detected a potentially dangerous client input value, and processing of the request has been aborted. This value may indicate an attempt to compromise the security of your application, such as a cross-site scripting attack. You can disable request validation by setting validateRequest=false in the Page directive or in the configuration section. However, it is strongly recommended that your application explicitly check all inputs in this case.

Exception Details:System.Web.HttpRequestValidationException: A potentially dangerous Request.Form value was detected from the client (noteTextBox="<H2><FONT size=6>asd...").

Anybody know how to deal with this while still allowing me to save the html?

<%@. Page...... ValidateRequest="false".....%>


I think the reason for this error was that someone could enter a <script> tag in your textbox with javascript code, and then if you grab that value from the form and display directly it on another page, the code in the <script> tag would be executed on your user's computer... this could be potentially bad. i usually turn the error off though, like the previous poster. If you HtmlEncode() anything that you display that ultimately came from the user, it should be ok to turn it off.


How do I HtmlEncode() this text?


dim myText as String = Server.HtmlEncode(yourTextbox.Text)

Trouble with connection string in web.config

I am attempting to access a connection string from the web.config file, but I am receiving a "The ConnectionString property has not been initialized" error. If I place the connection string inline with my code it works perferctly, but when I attempt to access it via the web.config file I run into trouble. I have listed my code below which is very simple, because I am just learning .NET

Any help is greatly appreciated...

<configuration>
<appSettings>
<add key="ConnectionString" value="Server=localhost;database=msdb;Trusted_Connection=yes" />
</appSettings>
</configuration
Sub Page_Load(Sender as Object, E as EventArgs)
Dim strConnectionString as string = ConfigurationSettings.AppSettings("ConnectionString")
Dim strSQL As String = "SELECT * FROM log_shipping_databases"
Dim MyConnection as new Sqlconnection(strConnectionString)
Dim MyCommand as new SqlCommand(strSQL, MyConnection)

MyConnection.Open()
MyDataGrid.DataSource = MyCommand.ExecuteReader()
MyDataGrid.DataBind()
MyConnection.Close()
End Sub

Bump, still stuck on this problem. Any help would be greatly appreciated.
Have you had anything work from your web.config file?? The only thing I can think of is that your IIS application is not configured correctly. If this is the case, your .aspx pages will work, but IIS will not know where to look for your web.config file. This may not be the case at all....but it is my best guess at your problem. Check your site in IIS an make sure your application is configured correctly. And also double check to see that your web.config file is in the root of said application.

Hope that helps

-Jason
Jason,

Thanks for the reply. I went into IIS and made sure everything was ok, and as far as I can tell it seemed to be set up correctly. However, I deleted the existing virtual directory and created a brand new directory and set up the application again. It is still not working as intended though.

I also attempted to obtain other information that was contained in the web.config file and that did not work either.

Lastly, I am creating all my .aspx files in the root directory and that is where web.config resides as well.

Can you think of a particular setting I can check to verify everything is set up correctly? Thanks for the input thus far.

-Corey
Have you imported System.Configuration?

If you are going to use ConfigurationSettings.AppSettings("ConnectionString") then you need to import System.Configuration. I usually import System.Configuration.ConfigurationSettings and then just use AppSettings("ConnectionString") so there is less code to write.
Yes, I have also tried that as well. Below is the complete code for my project.


<%@. Page Language="VB" %>
Imports System.Configuration

<script runat="server"
Sub Page_Load(Sender as Object, E as EventArgs)
Dim strConnectionString as string = ConfigurationSettings.AppSettings("ConnectionString")
Dim strSQL As String = "SELECT * FROM log_shipping_databases"
Dim MyConnection as new System.Data.OleDb.OleDbConnection(strConnectionString)
Dim MyCommand as new System.Data.OleDb.OleDBCommand(strSQL, MyConnection)

MyConnection.Open()
MyDataGrid.DataSource = MyCommand.ExecuteReader()
MyDataGrid.DataBind()
MyConnection.Close()
End Sub

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<asp:datagrid id="MyDataGrid" runat="server"></asp:datagrid>
</form>
</body>
</html


Delete any web.configs that are outside of your virtual apps.
This can cause problems.
So inside wwwroot there will be no web.config file, they will only be inside your applications folders.
HTH
Not that it matters in this case, but you got the syntax for importing a namespace wrong. It should have been:
<%@. Page Language="VB" %>
<%@. Import Namespace="System.Configuration" %>

It doesn't matter in this case, as it's not necessary. Your code, as shown, is sufficient to call information from web.config.

So, your problem is not in code. It is likely a setup problem. For example, the web.config file must go in the root folder of your Application. Like this:

c:\
\inetpub
\wwwroot
\MyApp
web.config
default.aspx

If you've placed it inside wwwroot, rather than the root of your own Application, this would cause your problem.

Hence, can you confirm that you've placed your web.config and your ASPX page in their own App folder, as shown? And that that app has been made a Web Application with IIS?
I think the following link could be useful.

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

The web.config is inheritable. This means you can have a web.config in wwwroot and in your application folder. When you call ConfigurationSettings.AppSettings("ConnectionString")
the MyApp web.config would be checked first. If that key isn't found then it would look in wwwroot. So, it is not required that you have a web.config in the app folder if you have one in wwwroot. I create a lot of applications that use a connection string so the connection string is placed in the wwwroot web.config that way it resides in one location. Then the web.config files in the app folder only hold application level settings.

Also, virtual roots or IIS applications do not affect this at all. I have tested it both ways. With or without a virtual root the web.config inheritance still works.

The last post is a good test but I don't think it's going to solve the problem. If you had a web.config in wwwroot and a connection string key in there, you wouldn't have to have a web.config in your application folder.

I actually am curious to see if the namespace correction mentioned above fixes things. SomeNewKid2, if he was using incorrect syntax on importing the namespace then I think it would matter, right? No namespace would mean no ConfigurationSettings.AppSettings exists to the application.
No, System.Configuration is a namespace that's implicitly imported with inline code. Hence, he can use ConfigurationSettings.AppSettings, without explicitly importing its namespace.

The way he had it meant it was simply considered literal text. No harm done, and it wouldn't have solved his problem even if his syntax was correct.

(I have used his own code to access a web.config. Works fine. The problem is not in his code.)
Below is where my web.config and default.aspx files reside:

c:\inetpub\wwwroot\training\web.config
c:\inetpub\wwwroot\training\default.aspx

Also, I have checked IIS to verify that it is set up as an application. I also deleted the virtual directory and setup it up as an application from scratch in IIS. I may very well be excluding a minor detail somewhere, but I can't seem to indetify it.

Thanks for all the help,
Corey
Back up your current default.aspx and web.config files. (Or just rename them temporarily.)

Try replacing your web.config with this very simple one:

<?xml version="1.0" encoding="UTF-8" ?>
<configuration
<appSettings>
<add key="ConnectionString" value="Server=localhost;database=msdb;Trusted_Connection=yes" />
</appSettings
<system.web>
</system.web
</configuration>

Now, replace your default.aspx with this modified version:

<%@. Page Language="VB" Debug="true" %
<script runat="server"
Sub Page_Load(Sender as Object, E as EventArgs)
Dim strConnectionString as string = ConfigurationSettings.AppSettings("ConnectionString")
Dim strSQL As String = "SELECT * FROM log_shipping_databases"
'Dim MyConnection as new System.Data.OleDb.OleDbConnection(strConnectionString)
'Dim MyCommand as new System.Data.OleDb.OleDBCommand(strSQL, MyConnection)

'MyConnection.Open()
'MyDataGrid.DataSource = MyCommand.ExecuteReader()
'MyDataGrid.DataBind()
'MyConnection.Close()
Message.Text = strConnectionString
End Sub

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<asp:datagrid id="MyDataGrid" runat="server"></asp:datagrid>
<asp:Label id="Message" runat="server" />
</form>
</body>
</html>

This code works fine on my machine. Let me know if it works okay on yours. (It should simply show the ConnectionString value that it retrieved from web.config.)
It prints the connection string to the browser:

Server=localhost;database=msdb;Trusted_Connection=yes
Which means it worked.

Well, the .aspx file is just a simplified version of your own. Which suggests that there is merely an error in your web.config file.

Since the web.config file is an XML file, it is very sensitive to syntax and proper nesting of statements.
You probably just have a statement in the wrong place.

Do you want to post the code for your web.config file?

Thursday, March 22, 2012

trouble with read method in oledbdatareader object

Public Function GetNextCounter(ByVal QueuePath As String) As Integer
Dim ObjConn as new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & QueuePath)
Dim intGetNextCounter as integer
Dim rdr as OleDbDataReader
Dim ObjCmd as new OleDbCommand("Select * FROM tblReportQueue_ID", ObjConn)

ObjConn.Open()
If rdr.Read then
rdr = ObjCmd.ExecuteReader()
intGetNextCounter = rdr.GetInt32(0)
else
intGetNextCounter = 90
end if
ObjConn.close()

GetNextCounter = intGetNextCounter
End Function

When I compile the page that this function is in, I get an error message saying "Object reference not set to an instance of an object." The error occurs on the line

If rdr.Read then

Can anyone give me a hand as to what went wrong? ThanksMove


rdr = ObjCmd.ExecuteReader()

Before you read rdr
i.e

rdr = ObjCmd.ExecuteReader()
If rdr.Read then
intGetNextCounter = rdr.GetInt32(0)
else
intGetNextCounter = 90
end if

Trouble with Response.Cookies

In Visual Studio.NET, I can't get the following code to compile:


public static bool setCookie(string cookiename, string cookievalue)
{
try
{
HttpCookie objCookie = new HttpCookie(cookiename);
Response.Cookies.Add(objCookie);
objCookie.Values.Add(cookiename,cookievalue);
}
catch( Exception e)
{
return false;
}
return true;
}

Visual Studio returns the following build error:

'System.Web.UI.Page.Response' denotes a 'property' where a 'class' was expected.

Any advice would be appreciated.

DougNot sure what the problem is. Have a feeling it is because you have to set the cookie's value before adding it.

As MS put it:
HttpCookie MyCookie = new HttpCookie("LastVisit");
DateTime now = DateTime.Now;

MyCookie.Value = now.ToString();
MyCookie.Expires = now.AddHours(1);

Response.Cookies.Add(MyCookie);

Have a look atthis for examples

HTH

Jagdip
Okay I tried rearranging the code per the suggestion, but still get the same error. Here's the updated code:


public static bool setCookie(string cookiename, string cookievalue)
{
try
{
HttpCookie objCookie = new HttpCookie(cookiename);
objCookie.Value = cookievalue;
Response.Cookies.Add(objCookie);

}
catch( Exception e)
{
return false;
}
return true;
}


try this:
httpcontext.current.response.cookies.add(objcookie)