| | |
operator error
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2006
Posts: 9
Reputation:
Solved Threads: 0
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");
}
}
}
}
}
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");
}
}
}
}
}
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)•
•
Join Date: Sep 2006
Posts: 9
Reputation:
Solved Threads: 0
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.
select count(*) as expr1
from tblPeople
where userid = @UserID
and passowrd = @Password.
•
•
•
•
It's basically the column name for the query below (typed dataset).
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)
int result = Convert.ToInt32(LogInfo.Expr1Column.ColumnName); if (result > 0)
Last edited by Inanna; Oct 9th, 2006 at 4:48 pm.
•
•
Join Date: Oct 2006
Posts: 16
Reputation:
Solved Threads: 1
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
Have a look at your LogInfo object in the watch window and let us know what it contains.
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.
![]() |
Similar Threads
- Error in the Operaror- function ?? (C++)
- Passing a matrix from main function to user defined function. (C++)
- compilation errors (C++)
- Automatic Shuffle Master (C++)
- Error in compiling matrix (C++)
- looking for magic website. (Web Browsers)
Other Threads in the C# Forum
- Previous Thread: Combo Box
- Next Thread: Saving Excel Spreadsheet using ADO.net gives inconsistent results
| Thread Tools | Search this Thread |
.net access ado.net algorithm array barchart bitmap box broadcast buttons c# chat check checkbox client color combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees development display draganddrop drawing encryption enum event excel file files form format forms function gdi+ httpwebrequest image index input install java label list listbox listener mandelbrot math mouseclick mysql native networking operator path photoshop picturebox pixelinversion pixelminversion post prime programming radians regex remote remoting richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml






