Here's an example from a quick app I built. So here you go I created a class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public class IsBaseUser
{
SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["GridAutoConnectionString"].ToString());
public bool VerifyBaseUser(string uName)
{
using (cn)
{
cn.Open();
using(SqlCommand cmd = new SqlCommand("SELECT * FROM tblGridAutoUsers WHERE username = '" + uName + "' AND rolename = 'Base'", cn))
{
SqlDataReader reader = cmd.ExecuteReader();
if (reader.HasRows)
{
cn.Close();
return true;
}
else
cn.Close();
return false;
}
}
}
}
Then I used that class in my program:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
IsBaseUser b = new IsBaseUser();
if (b.VerifyBaseUser(TextBox1.Text) == true)
{
Label1.Text = "This is a base user";
}
else
{
Label1.Text = "Check your spelling.";
}
}
}
I simply used a button, a textbox, and a label. This works just fine and should get you going in the right direction:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
<br />
<br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:GridAutoConnectionString %>"
SelectCommand="SELECT * FROM [tblGridAutoUsers]"></asp:SqlDataSource>
</form>
</body>
</html>