whathappened9
01-03-2007, 06:01 PM
Hello,
I have SQLEXPRESS on my machine with a database named cccr. Through database explorer it is connected, but not when I run the website. here is the relevant code
static string connStr = "server=myMachine\\SQLEXPRESS;database=cccr;";
System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(connStr);
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
lblError.Text = "";
string user = txtUser.Text.Trim();
string pass = txtPass.Text.Trim();
string strSQL = "SELECT count(KFUPM_ID) FROM Admin WHERE KFUPM_ID = '" + user + "' AND PassW = '" + pass + "'";
SqlCommand dbCommand = new SqlCommand();
dbCommand.CommandText = strSQL;
dbCommand.Connection = conn;
int num = 0;
conn.Open();
try
{
num = Int16.Parse(dbCommand.ExecuteScalar().ToString());
}
catch (Exception) { }
conn.Close();
Whenever I click , I get unhandled exception pointing at
" conn.Open " . I would appreciate any comments.
thank you
I have SQLEXPRESS on my machine with a database named cccr. Through database explorer it is connected, but not when I run the website. here is the relevant code
static string connStr = "server=myMachine\\SQLEXPRESS;database=cccr;";
System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(connStr);
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
lblError.Text = "";
string user = txtUser.Text.Trim();
string pass = txtPass.Text.Trim();
string strSQL = "SELECT count(KFUPM_ID) FROM Admin WHERE KFUPM_ID = '" + user + "' AND PassW = '" + pass + "'";
SqlCommand dbCommand = new SqlCommand();
dbCommand.CommandText = strSQL;
dbCommand.Connection = conn;
int num = 0;
conn.Open();
try
{
num = Int16.Parse(dbCommand.ExecuteScalar().ToString());
}
catch (Exception) { }
conn.Close();
Whenever I click , I get unhandled exception pointing at
" conn.Open " . I would appreciate any comments.
thank you