Home » Visual Studio

Custom Code adding function count()


3 Answers Found


Answer 1

Hi sunnyplace,

Thanks for posting your issue here!

Could you be more specific please?



Answer 2

sorry, I solved the problem.

Answer 3

Hi Angie,

Thanks for your feedback!

We will appreciate it if you can share the solution so that the answer can be found and use by other community members having similar questions.




Let say I am working in a form, and I had to this

Dim par1 as string = "something"

I want pass par1 to update sql statement, and I am not using AddParameter

So, I had to add single quotes, the par1 will be
par1 = "'" + par1 + "'"

instead of doing the above, I was thinking in

par1 = par1.ToString.AddSingleQuote


par1 = par1.AddSingleQuote

Either to add "AddSingleQuote" to "ToString" method, or make it available for every variable of type "String"

Can that be done?






I want to be able to add new functions for actions in the Biztalk 2009 Rules Engine Composer. Is this possible?


what is the best way to connect to an SQL database from an InfoPath web part form custom code? i mean does the connection string really have to be included in the code (just like here http://table38.com/ns/?p=17) or can the custom code access the  SharePoint's web config? is it good to add a db connection string in the sharePoint's web config file?


In a site within a site collection, using SharePoint Designer 2010 we have created custom Display, Edit and View forms and assigned them to the Item content type of a custom list as it's default forms. When looking at the Forms property of the list, I can see all six forms listed: the three original forms (DispForm.aspx, EditForm.aspx, NewForm.aspx) and the three custom forms (displayifs.aspx, editifs.aspx, newifs.aspx).

Each site in the site collection has this custom list and I want to add these three custom forms to the custom list in each site in the collection as the default forms for items. In code I have tried copying the files from the Item subfolder of the first custom list to the Item subfolder in each list in each site, and then setting the properties for the Item content type's default forms to point to these new files (e.g DisplayFormUrl = "~list/Item/displayifs.aspx"; EditFormUrl = "~list/Item/editifs.aspx"; NewFormUrl = "~list/Item/newifs.aspx";) and I have also copied the fourth file template.asxn to this folder in each list. However, I have not found how to add these new files to the Forms property of the list iteself, as this property is read-only. It still only contains the three default forms. Is this possible to do in code?

When I try to open the Display form or Edit form in the list, the correct file is referenced in the url and the dialog is raised without errors, but the infopath Form itself is not being rendered. Is this because I have not added these forms to the Forms property of the list? If so, how can I add them programmatically?

Is there some property or setting I am not configuring in order to render the custom forms correctly?




I'm creating a custom control which inherets the BindingNavigator.

I need do add one ToolStripButton at specific posistion (9 element) on the ToolStrip of the BindingNavigator.

So, I wrote the following code:

Dim tsb AsNew ToolStripButton
With tsb
  .Name = "BindingNavigatorUndoChanges"
  .Image = My.Resources.UndoChanges
  .ToolTipText = "Undo changes"EndWithMe.Items.Insert(9, tsb)

My question is: In which event of the custom control should I put this code?

Many thanks for any kind of help.





I have a custom Outlook (contact) form with various (vbscript) procedures already in place.

I have now also built a vsto Outlook add-in to update a selection of items, and need to trigger/call one of the existing vbscript/form procedures when I update the item. I cannot find a way to do this...does anyone have an idea, or can point me in the right direction?  Even if I could trigger a form event like Item_open or custompropertychange would work for me.

I am using VS 2010, writing a solution for Outlook 2007.

I would prefer not to duplicate the procedures already in place, as they will still be used, and and ongoing maintenance would be best kept to a single point.




Hi everyone,

We have just migrated a big asp.net project from 1.1 to 3.5 framework.

We have tons of typed dataset objects.

After migration, the Locale property of dataset objects become a problem.

This code in the generated code of dataset objects. (designer.cs)

  this.Locale = new global::System.Globalization.CultureInfo("en-US");

But i want my datasets to work with CurrentCulture, not static culture defined designer.cs file.

So i tried to find a method to override the static Locale property on the dataset.

This method should work on new dataset definition.

DataSet ds = new DataSet(); //i need to catch the appropriate method.

But i could not find any appropriate method to override. in the partial file of course.

I found PropertyChanging method but, this method fires after InitClass method, which sets the Locale property to English.

How can i handle this situation.

Note 1 :I dont want to set Locale property where dataset is defined.

This is lots of place to add.

Note 2 : I tried to find and replace the Locale property for all datasets.But after adding a new column to dataset, the code added to designer.cs file again at .




<!-- [if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:TrackMoves/> <w:TrackFormatting/> <w:PunctuationKerning/> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:DoNotPromoteQF/> <w:LidThemeOther>EN-IN</w:LidThemeOther> <w:LidThemeAsian>X-NONE</w:LidThemeAsian> <w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript> <w:Compatibility> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <w:DontGrowAutofit/> <w:SplitPgBreakAndParaMark/> <w:DontVertAlignCellWithSp/> <w:DontBreakConstrainedForcedTables/> <w:DontVertAlignInTxbx/> <w:Word11KerningPairs/> <w:CachedColBalance/> <w:UseFELayout/> </w:Compatibility> <m:mathPr> <m:mathFont m:val="Cambria Math"/> <m:brkBin m:val="before"/> <m:brkBinSub m:val="--"/> <m:smallFrac m:val="off"/> <m:dispDef/> <m:lMargin m:val="0"/> <m:rMargin m:val="0"/> <m:defJc m:val="centerGroup"/> <m:wrapIndent m:val="1440"/> <m:intLim m:val="subSup"/> <m:naryLim m:val="undOvr"/> </m:mathPr></w:WordDocument> </xml><![endif]--><!-- [if gte mso 10]> <mce:style>

I develop one automation excel add in using visual studio 2008 ,c#  by following the instructions from

(http://www.emoreau.com/Entries/Articles/2010/06/Creating-Excel-Add-in-with-VBnet-or-C.aspx).Found some similar set of instructions in Microsoft site also.


And successfully create the user defined function and that is appeared on my excel function wizard  .

Now what i need is a way  to specify function descriptions, argument descriptions, or help for Automation Add-in functions in the Function Wizard. I search for this and find no helpful resources. (Found one solution using a 3rd party .dll and is not feasible (http://em-risk.com/groups/exhale/wiki/exhale-c.aspx)

Is there any way to do this (I need a solution using the visual studio 2008 ,c# class library e.t.c. and not using VBA )




I have a table with varchar(max) column. This column stores all the function calls to application. Example


The above output shows the requests of User 1 and 2. User 1 called SUM, AVG and COUNT functions once. User 2 called SUM once and AVG, Count twice. I need to calculate these counts through Regular expression in SQL Server 2005.

Following is script for table and data generation:

CREATE TABLE [dbo].[UserRequests]
 [UserID] [int] NOT NULL,
 [Requests] [varchar](255) NULL

insert into [dbo].[UserRequests] values (1, 'SUM(SALARY); AVG(LEAVES)/COUNT(DAYS);')
insert into [dbo].[UserRequests] values (2, 'SUM(SALARY)/AVG(SALARY); AVG(LEAVES)/COUNT(DAYS); COUNT(EMPLOYEES);')

Any suggestion or idea would be highly admired.

PS: if someone has another optimized solution for this problem, kindly suggest that as well.



I want to know the meaning of function DisplayCharCount, span Counter ,documents.form[0],RegisterClientScriptBlock and Bolded line in the following programm and also let me know what is happening in this programm


{string scriptText="";scriptText+="function DisplayCharCount(){";scriptText+="spanCounter.innerText="+"document.forms[0].TextBox1.value.Length";scripttext+="}";ClientScript.RegisterClientScriptBlock(this.GetType(),"CounterScript",scriptText,true);TextBox1.Attributes.Add("onkeyup","DisplayCharCount()");LiteralControl("<span id=\"spanCounter\"></span>");PlaceHolder1.Controls.Add(spanLiteral);}}





I am needing help writing a query that only counts certain fields based on previous record.  Let me explain:



PropIDBooking Date Booking Code

11/1/11 0

22/2/11 1

33/3/11 2

44/4/11 1

55/5/11 1

66/6/11 0


So I would like to Count all of the booking codes with Booking code ID =1 .  If a query is ran against this, you will get three.  Very straightforward.  My problem is I don;t want to count the booking code =1 if the previous record was 1 as well.  So when I run the new query, I want the answer to be 2 not three.

This one record set for a property.  I have to apply this logic to multiple properties in the same table.

Any direction/hints will be very appreciated.




Hi Team,

How can we find out count sp's, userdefined functions, triggers in one Database  (No.of)


can any body plz help me.


I have a Custom Principal class that Implements System.Security.Principal.IPrincipal and a Custom Identity class that Implements System.Security.Principal.IIdentity. So when a user successfully login to my windows form application, I set My.User.CurrentPrincipal = CustomPrincipal, which worked great until I started adding custom functions to my Principal and Identity classes.

Now, when I try to access them (i.e. My.User.CurrentPrincipal.Identity.UserType), I get an error similar to the one listed below:

'UserType' is not a member of 'System.Security.Principal.IIdentity'

After searching in quite a few places for a solution, I finally found something that works:

Dim x As MyCustomIdentity = DirectCast(My.User.CurrentPrincipal.Identity, MyCustomIdentity)

However, I would like to know if there is an efficient way to accomplish this task and if it's possible to access my custom functions directly without having to use DirectCast in every form.

Any suggestions or Ideas will be greatly appreciated.

I have used an example to allow C# code to be compiled at runtime via my application using CodeDomProvider, and it works as far as allowing me to run basic code, but how do I expose a custom class and allow the compiler to use them? The custom classes are not in a seperate dll and Id on't want them to be.


I'm a newbie using TFS and one of the jobs I have been assigned is to find the total lines of code in my project that relate to enhancements. We already have a code base upon which we are implementing some new enhancements. The code for the enhancements has already been checked in into TFS. Also later checkin's contain bug fixes and missed comments.

What I was looking for was a way to count the original lines of code that have gone in for the enhancements. Unfortunately, I have not been able to rake up enough material to guide me to do this.

I have VS 2008 and 2008 Team Explorer on my system.

Can anyone please help me ?



Im trying to run this code, but im gettin an error:

include <iostream>
namespace std;

return 0;

the error:

1>------ Build started: Project: test2, Configuration: Debug Win32 ------

1> test2.cpp

1>test2.cpp(4): warning C4627: '#include <iostream>': skipped when looking for precompiled header use

1> Add directive to 'StdAfx.h' or rebuild precompiled header

1>test2.cpp(12): fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "StdAfx.h"' to your source?

========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

cant i use "count" and "endl"??
many other codes dont work,



I am not able to get the number of lines in a method while developing a code rule which would enforce a maximum limit on the line count. I have the complete details in this link. http://stackoverflow.com/questions/3650865/visual-studio-code-analysis-creating-a-new-rule-to-count-number-of-lines-in-met I am sure I am making a stupid mistake somewhere in this but not able to figure out what. Could you please provide me any direction on this.

Thank you very much for the help.



I am here trying to get the Alert count for a user in a site collection(including all the sub sites). The below code only returns Alert count of a root level site. I want all Alerts for a particular user.

SPUserCollection users = web.AllUsers;

foreach (SPUser user in users)
 foreach (SPAlert alert in user.Alerts)





For Example:

If my site collection has 5 sub sites

1) ROOT URL : http://xyz:1001

User ABC has 2 Alerts defined at this level

2) Sub site URL : http://xyz:1001/Sub1

User ABC has 1 Alert defined here

The above code only returning 2. I want total Alert count, that is 3.


Please help me. I appreciate it.



I have developed a custom debug engine and wanted to know how I could get the count of break points that have been visually set in the editor.  right now I get all the pending break points through




this causes some problems for me, and it causes some synchronization problems with my external debugger.  I wanted to know how to enumerate all the berakpoints that have been visually set in the editor before they get called by







This is a very frustrating problem. I have a big WCF service with a lot of methods. When I try to add the reference in VS I get:

The maximum nametable character count quota (16384) has been exceeded while reading XML data. The nametable is a data structure used to store strings encountered during XML processing - long XML documents with non-repeating element names, attribute names and attribute values may trigger this quota. This quota may be increased by changing the MaxNameTableCharCount property on the XmlDictionaryReaderQuotas object used when creating the XML reader. Line 1, position 332845.

I can clearly see in the web config this line:


maxBytesPerRead="4096"maxNameTableCharCount="16384" />

but no matter what I set maxNameTableCharCount to, it errors because this entry is not added until the reference is successfully added. The advanced button on the add service reference screen doesn't have any options to change this value.

What can I do? Please don't tell me to use svcutil to do this manuallly. Well, if you do, at least tell me which parameters to specify.



<< Previous      Next >>

Microsoft   |   Windows   |   Visual Studio   |   Sharepoint   |   Azure