4
Answers

Sound wrong connection with my DbName

Ask a question

Hi!

There is a little bit think I didnt understand. I should be wrong in my way.
This is my log in interface. When I leave textbox blank he let you inform that textbox are blank, etc...
Then when I introduce the username and password. Even it's correct its bugging on this line of code:

SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["mfwamba"].ConnectionString);

After that I do try this:


SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["localhost\\sqlexpress\\mfwamba"].ConnectionString);

Even this line of code that's not work.

I put the right that DBconnection. But its does not work. What's happen. Need help please:


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


protected void btnSubmit_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["mfwamba"].ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand("select * from UserInformation where UserName =@username and Password=@password",con);
cmd.Parameters.AddWithValue("@username", txtUserName.Text);
cmd.Parameters.AddWithValue("@password", txtPWD.Text);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if(dt.Rows.Count>0)
{
Response.Redirect("Details.aspx");
}
else
{
ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('Invalid Username and Password')</script>");
}
}


Answers (4)