Invalid operator for data type. Operator equals add, type equals bit

When I wrote a sql server stored procedure, got a error message about bit data type when I tried to run this script:

Invalid operator for data type. Operator equals add, type equals bit.

The error msg is saying that a bit type parameter cannot be concatenated against the 2 strings. Cast it as varchar or nvarchar

The final script is like the following:


IF EXISTS(SELECT name FROM sysobjects WHERE name = ‘procADGetStatus4Email’ AND type = ‘P’)
DROP PROCEDURE dbo.procADGetStatus4Email

Creation Date: 19 June 2007
Author:        XXXXXX
Description:     Get Status List
Tables:     StatusDomain
CREATE   PROCEDURE dbo.procADGetStatus4Email
@StatusCode    smallint = NULL,
@EmailSendInd    bit = NULL

Declare @strSQL as nvarchar(2000)
Declare @strSQLwhere as nvarchar(2000)

select @strSQL = ‘select DISTINCT A.StatusCode,  A.Member, A.StatusShortDesc, A.StatusLongDesc,’
select @strSQL = @strSQL + ‘A.CreatedDate, A.UpdatedDate,  A.UserID, A.EmailSendInd’
select @strSQL = @strSQL + ‘ FROM dbo.StatusDomain A ‘

select @strSQLwhere = ‘ WHERE A.StatusCode > 0 ‘

IF @StatusCode is Not Null and @StatusCode <> ‘-1’
select @strSQLwhere =  @strSQLwhere + ‘ And (A.StatusCode =  ‘ + cast(@StatusCode as nvarchar) + ‘)’

IF @EmailSendInd is Not Null
select @strSQLwhere =  @strSQLwhere + ‘ And (A.EmailSendInd =  ”’ + cast(@EmailSendInd as nvarchar) + ”’)’

select @strSQL = @strSQL+ @strSQLwhere

select @strSQL = @strSQL + ‘ ORDER BY A.StatusCode ‘

print @strSQL

EXEC  sp_executesql @strSQL


GRANT  EXECUTE  ON [dbo].[procADGetStatus4Email]  TO [LMS_Readers]

How To Create an ASP.NET Application from Multiple Projects for Team Development

I got this good article from Microsoft:

How To Create an ASP.NET Application from Multiple Projects for Team Development


I copied all their content in my Blog before, and put there , nobody told me sth. about it, but yesterday I transfer my old blog to this new one, sb. else posted comment and let me know seems I can not copy all content here.

Ok, let me just copy their Summary and give the left to redirect their site.  But I am just worried about they change their URL and I will lost this article. I really need it.


loadTOCNode(1, ‘summary’); This article describes how to make multiple ASP.NET projects participate in the same Web application.

You may find it useful to separate a large Web application project into multiple projects for team development of ASP.NET Web applications in Microsoft Visual Studio .NET. Microsoft recommends that you use source control software, such as Microsoft Visual SourceSafe, in all scenarios.

Developing a large Web site frequently involves several developers. These developers must be able to work on specific sections of a Web application without interfering with one another and yet still be able to use each other’s work as the project progresses. To do this, you can use a single project in a Visual Studio .NET solution. You can also separate a Web application into multiple projects by dividing the development project into units to make development easier.

You can develop Web applications in single project or multi-project Visual Studio .NET solutions. The advantages and disadvantages of each method are outlined in the sections to follow.

(… Please go to MS site to read more…. )

ASP.NET get page name, visiting user name, function name, form name:

1: string username = Me.Page.User.Identity.Name
2: string username = System.Environment.UserName()

1: string pagename = Me.Page.GetType().Name()
2: string pagename = Request.Path.Substring(Request.ApplicationPath.Length + 1)

1: string functionname = System.Reflection.MethodBase.GetCurrentMethod().Name

1: string formname = Request.Path.Substring(Request.Path.LastIndexOf(“/”)+1);

Cannot convert type ‘ASP.login_aspx’ to ‘System.Web.UI.WebControl’

If you have used a Page that effectively uses a codebehind classname
that is the same as say the Login control, that is Login, e.g. your
page was called Login.aspx, then when you pre-compile (publish) the web
site as an updateable web site, the aspx is retained and tries to
compile against a type called Login in the code behind. It does not
resolve to be that in the codebehind assembly

Try using a classname for your codebehind and defined in the inherits
that does not clash with a type in System.Web, e.g. LoginPage, or
qualify the class and therefore the inherits statement with a
namespace, e.g.
in the .aspx file:

<%@ page … inherits=”MyNameSpace.Login” %.
in the code behind file:

namespace MyNameSpace

{ public partial class Login : System.Web.UI.Page





how to get aspx page username ?

in vb its system.environment.username – whats the equivalent in aspx with
code behind (VB) ?


In the codebehind of your aspx code, you could use:

Page.User.Identity.Name ;

In a custom class, you could use:


thanks but niether seems to work – aspx accepts it but it does nothing!


It depends how you would like to use it.

If you want to get the Windows username you have to make sure you disabled
anonymous access in IIS.

If you use forms authentication you can make a custom principal:
System.Security.Principal.GenericIdentity identity = new
System.Security.Principal.GenericIdentity(“testUse rName”);
System.Security.Principal.GenericPrincipal principal = new
System.Security.Principal.GenericPrincipal(identit y,new string[]{

Context.User = principal;

Validation of ViewState Mac failed in ASP.NET 2

I met this Exception when I create a .mobi application followed the new policy of .mobi (I think it is WAP 2.0). I searched Google and got the following article, then I copy to here ((from : Later I will try to use the solution for my application

If you get this Exception

[HttpException (0x80004005): Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.]


* you know *for sure* that you aren’t using a web farm
* it seems that it appears when using built-in databound controls such as GridView, DetailsView or FormView which utilize DataKeyNames.
* it appears if you have a large page which loads slowly for any reason

Paypal STANDARD Website Payment Walkthrough?

Paypal STANDARD Website Payment Walkthrough?

Here is from a question about Commerce Starter Kit ( maybe it is can used for any e-commerce website code to setup Paypal payment.

Paypal STANDARD Website Payment Walkthrough?

To setup a fictitious Paypal account in the Sandbox and confirming the account:

1. Log into the Developer Central website at
2. This will bring you to the Developer Central homepage.
3. Click on the Sandbox link found on the right side of the page or the tab found at the top.
4. This will list your fictious sandbox accounts.  To create a new one, click on Create Account.
5. When you click Create Account, it will open a new page of the Register a New Paypal account on the Sandbox environment.
6. You may select one of three account types (casual shoppers, casual sellers, or business owners)
7. For this example, let’s select casual shopper by clicking on the Start Now button
8. Enter in the pertinent information on the Create A Paypal account page and click on the “I Agree, Create My Account”.
9. This will take you to the Account Sign Up results page.
10. It now tells you to confirm your email address… Go back to the Developer Central page where the Sandbox tab is.  Make sure to click the tab again to refresh the list of test accounts with the new account showing up on the list!
11. Now… click on the Email tab found just two tabs to the right of the sandbox tab – this is where you will find all the email coming to the new fictitious email box.  You will see an email there with the subject Activate Your Paypal account.  Click the link of the “email”.
12. A fake email should popup on a new browser window – copy the confirmation number to the “clipboard”
13. Go back to the Sandbox tab, and select the new test account and click the Launch Sandbox button. Sign in to the sandbox with the new test account email address and password by clicking the Login button.
14. To the left you will see a link to “Confirm Email” – click it.
15. Then click the link… “Click here if a link DOES NOT appear in the email”
16. Paste the confirmation number (saved in the clipboard) into the field and click the Confirm button.
17. The account is NOW confirmed.  You may now click on Continue or Skip to do more setup for the account.

Hope this helps.

A button style HyperLink in ASP.NET

<asp:HyperLink ID=”linkCountry” runat=”server”
NavigateUrl='<%# “CountryLst.aspx?ContinentID=” + DataBinder.Eval(Container.DataItem,”continentid”) %>’
Text='<%# DataBinder.Eval(Container.DataItem, “continentname”) %>’
Font-Bold=”True” ForeColor=”Black” Font-Size=”Medium” BorderWidth=”3px” BackColor=”LightGray” BorderStyle=”Outset” Width=”83px” style=”TEXT-DECORATION: none”  >

Generating Client-Side Script for Postback


Only two HTML form elements (button and image button) cause form postback. If your custom control renders an HTML element that does not cause postback (such as a text box or a link button) and you want the control to initiate postback, you can program this in ASP.NET through an event architecture that relies on client-side script (JScript, JavaScript).

Control developers need to make a few small changes to their controls to enable this postback mechanism. The following code fragment shows (in bold) the code that must be added to the Render method of a control to initiate postback.

protected override void Render(HtmlTextWriter output) {
                  output.Write("<a  id=\"" + this.UniqueID + "\" href=\"javascript:" + Page.GetPostBackEventReference(this) +"\">");
                  output.Write(" " + this.UniqueID + "</a>");
[Visual Basic]
Protected Overrides Sub Render(output As HtmlTextWriter)
   output.Write("<a  id=""" & Me.UniqueID & _
         """ href=""javascript:" & _
         Page.GetPostBackEventReference(Me) & """>")
   output.Write(" " & Me.UniqueID & "</a>")
End Sub

The GetPostBackEventReference method emits client-side script that initiates postback and also provides a reference to the control that initiated the postback event.

To understand what the GetPostBackEventReference method does, compile the code in the next section, Postback Using Client-Side Script Sample, and request the accompanying .aspx page in your browser. If you view the source for the rendered page using your browser’s View Source command, you will see the following HTML and script. (The actual values of the name and the ID attributes of the form will differ, and so will the value attribute of the hidden variable.)

<form name="ctrl2" method="POST" action="MyLinkButton.aspx" id="ctrl2">
<input type="hidden" name="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" value="dDwtMjI1NTgwNDE2Ozs+eIZ+AfRvoCj1nWimbh+zPv/rKNg=" />                  
Here is the custom link button.<br>
<a  id ="Link" href="javascript:__doPostBack('Link','')"> Link</a> 
<input name="TextBox" type="text" value="Click the link" id="TextBox" style="background-color:Cyan;width:200px;" /> 
<script language="javascript">
      function __doPostBack(eventTarget, eventArgument) {
            var theform = document.ctrl2
            theform.__EVENTTARGET.value = eventTarget
            theform.__EVENTARGUMENT.value = eventArgument
// -->

The elements in bold in this example — two hidden fields and the client-side script method — are added by the ASP.NET page framework. The hidden form fields indicate which server control to post to and optionally specify an argument to pass. The client-side script method is used to set the hidden fields and causes the form to be submitted to the server. For a complete sample, see Postback Using Client-Side Script Sample.

See Also

Postback Using Client-Side Script Sample

Get relavated value of selected row of GridView using javascipts

So, here is the story. I have a GridView which contains the ASP.NET CheckBox control. Each row also have the primary key of the database table. Now, I need to get the ID of the selected checkbox using JavaScript. I used a hidden field to store the ID of the row (The row is hidden and the user cannot see it on the display but you can see the value if you do the view source). Now, I like to access the hidden field of the selected row of the GridView.



<asp:CheckBox id=”chkSelect” runat=”server” />

<asp:HiddenField ID=”hfID” runat=”server” Value='<%# Eval(“ID”) %>’ />



And here is the JavaScript code:

function GetIDFromHiddenField()


var elements = document.getElementsByTagName(“INPUT”);

var ID;

var count = 0;

for(i=0; i< elements.length; i++)


if(elements[i].type == ‘checkbox’)


if(elements[i].checked == true)


count = count + 1;

ID= elements[i].nextSibling.nextSibling.value;




// check if more then one exam is selected. If so, then alert the user

if(count > 1) { alert(‘Please only select a single item from the list’); return (-1); }

else return ID;


Althought I am only allowing the user to select a single item I am sure you got the basic idea.