Converting Database Connections from ASP to ASP.NET

liunx

Guest
I'm having a difficult time in creating a database connection from ASP to C# ASP.NET. Here is the code I want to convert

Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open GetConnStr("DB")

sql="SELECT * FROM AdminUsers WHERE Username='"&username&"' AND Password='"&password&"'"
Set RS=Conn.Execute(sql)


Can anybody point me in the right direction?

Thanks,
JoshI'm wondering the same thing? Does anybody know how? Is it possible (well, duh it is)?i'm assuming u use sql server....


using System.Data.SqlClient;
using System.Data;

private string connectionString; //value ommited
string sql="SELECT * FROM AdminUsers WHERE Username=username AND Password=password";

SqlConnection conn = new SqlConnection(connectionString);
SqlDataReader reader = null;

conn.Open();
SqlCommand cmd = new SqlCommand(sql,conn);

cmd.Parameters.Add("@username", this.username); //global value
cmd.Parameters.Add("@password", this.password); //global value

reader = cmd.ExecuteReader();
if (reader.Read())
//do whatever with ur data...

reader.close();
conn.close();
 
Back
Top