944,028 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 3427
  • C# RSS
Oct 9th, 2006
0

operator error

Expand Post »
Hello everyone,

I have the following code behind for a login page. When I compile, I am getting the following error. It won't allow me to use the operator > in the line below in red. Can someone please tell me why? Expr1 basically returns a number - either 1 (account exist) or 0 (account doesn't exist). Thanks for your help...


Error:
Operator '>' cannot be applied to operands of type 'System.Data.DataColumn' and 'int'.


Login.aspx.cs:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.Security;
using System.Data.SqlClient;
using System.Configuration;
using CriteriaTableAdapters;

namespace TestLogin
{

publicpartialclassWebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox UserID;
protected System.Web.UI.WebControls.TextBox Password;
protected System.Web.UI.WebControls.Button cmdSubmit;

privatevoid Page_Load(object sender, System.EventArgs e)
{

}


protectedvoid cmdSubmit_Click(object sender, System.EventArgs e)
{

string UserID = string.Empty;
string Password = string.Empty;

UserID = ((TextBox)Login1.FindControl("UserID")).Text;
Password = ((TextBox)Login1.FindControl("Password")).Text;

if (Page.IsValid)
{
tblPeopleTableAdapter LoginAdapter = newtblPeopleTableAdapter();

Criteria.tblPeopleDataTable LogInfo = LoginAdapter.GetDataBy(UserID, Password);


// Redirect if we succeeded

if (LogInfo.Expr1Column > 0)
{
Response.Redirect("Default.aspx");
}
else
{
Response.Redirect("SignInError.aspx");
}

}

}
}
}
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kathy78 is offline Offline
9 posts
since Sep 2006
Oct 9th, 2006
0

Re: operator error

my quess is Expr1Column is the name of a function, if that is correct then you need to add the parentheses
if (LogInfo.Expr1Column() > 0)
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,953 posts
since Aug 2005
Oct 9th, 2006
0

Re: operator error

Hello Ancient Dragon - thank you for your reply. Expr1Column is a "property". It's basically the column name for the query below (typed dataset). I am very new to .net so I may be wrong at explaining things....hope you understand what I'm trying to say:

select count(*) as expr1
from tblPeople
where userid = @UserID
and passowrd = @Password.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kathy78 is offline Offline
9 posts
since Sep 2006
Oct 9th, 2006
0

Re: operator error

Quote ...
It's basically the column name for the query below (typed dataset).
One thing I know for sure is that I'm not smart enough to use typed datasets. They've given me so much trouble that I'm more productive when I write the underlying code for them manually. :rolleyes:

But! The problem is that Expr1Column evaluates to a DataColumn object and it's not compatible with int. I can't really figure out why you're tryin' to compare a column with an integer, the only thing I can think of is that the count is the name of the column and you're tryin' to see if it's bigger than 0. If that's how it is then this'll work.
C# Syntax (Toggle Plain Text)
  1. int result = Convert.ToInt32(LogInfo.Expr1Column.ColumnName);
  2.  
  3. if (result > 0)
I can't begin to imagine why you would want to do somethin' like that though. :p
Last edited by Inanna; Oct 9th, 2006 at 4:48 pm.
Reputation Points: 53
Solved Threads: 6
Junior Poster in Training
Inanna is offline Offline
90 posts
since Sep 2006
Oct 9th, 2006
0

Re: operator error

Your query will evaluate to a 1 or a 0 into Expr1 but it does not return an integer it returns a table which is assigned to your LogInfo object.
That table will (i guess) contain the user name and password.
I suggest that you comment out the code causing the problem and debug to the line

Criteria.tblPeopleDataTable LogInfo = LoginAdapter.GetDataBy(UserID, Password);


Have a look at your LogInfo object in the watch window and let us know what it contains.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
peterbyrne is offline Offline
16 posts
since Oct 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Combo Box
Next Thread in C# Forum Timeline: Saving Excel Spreadsheet using ADO.net gives inconsistent results





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC