Hello everyone,

I am using VS2005 (C#) and have the following code behind for my login page. When I try to compile it, I get the following error on the line in bold below. Seems like I need to convert "UserName" and "Password" to strings. Can someone please help me with this?

Thanks,
Kathy

error
Argument'1':  cannot convert from 'System.Web.UI.WebControls.TextBox' to 'string'


code behind
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 LoginInfoTableAdapters;



namespace LoginTest
{


public partial class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox UserName;
protected System.Web.UI.WebControls.RequiredFieldValidator rvUserValidator;
protected System.Web.UI.WebControls.TextBox Password;
protected System.Web.UI.WebControls.RequiredFieldValidator rvPasswordValidator;
protected System.Web.UI.WebControls.Button cmdSubmit;
protected System.Web.UI.WebControls.ValidationSummary Validationsummary1;
protected System.Web.UI.WebControls.Label lblMessage;
protected System.Web.UI.WebControls.Label lblMessage2;


private void Page_Load(object sender, System.EventArgs e)
{


}


protected void cmdSubmit_Click(object sender, System.EventArgs e)
{
if (Page.IsValid)
{
tblPeopleTableAdapter LoginAdapter = new tblPeopleTableAdapter();


LoginInfo.tblPeopleDataTable Criteria =
LoginAdapter.GetDataBy(UserName.Text, Password.Text);
this.GridView1.DataSource = Accounts;
this.GridView1.DataBind();


}


}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{


}
}
}

Recommended Answers

All 4 Replies

You are passing a string. What does LoginAdapter.GetDataBy look like?

Thanks Inanna for your reply. I am very new to .net so let's see if I can try to explain this to you. I created a new dataset via the TableAdapter Query Configuration Wizard and the query for the GetDataBy method is below:

SELECT COUNT(*) AS Expr1
FROM tblPeople
WHERE (UserName = @UserName) AND (Password = @Password)

Please let me know if this is what you're looking for...

Thanks,
Kathy

It's hard to say. Harder still 'cause I don't work with TableAdapters. I do my stuff by hand... :( Can you paste the GetDataBy method?

Argument'1': cannot convert from 'System.Web.UI.WebControls.TextBox' to 'string'

The error message should give you the solution.
Either:
Argument 1 expects a 'System.Web.UI.WebControls.TextBox' object and is receiving a string or vice-versa

What data types are the arguments to your function GetDataBy?

If they are strings then your code should work.

If they are TextBox objects then try this:
LoginAdapter.GetDataBy(UserName, Password);

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.