Hi
public partial class Form1 : Form
{
string ConnectionString = ConfigurationSettings.AppSettings["cnn"];
string str;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void Btn_Click_1(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConnectionString);
con.Open();
str = "select count(*) from temp where usrname='" + txtusername.Text.Trim() + "' and usrpassword='" + txtpassword.Text.Trim() + "'";
SqlCommand cmd = new SqlCommand(str, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "login");
long x;
x = Convert.ToInt64(cmd.ExecuteScalar());
if (x == 1)
{
MessageBox.Show("Hello");
}
else
{
MessageBox.Show("Invalid UserName & Password");
}
con.Close();
}
}
Error : The connectionstring property has not been initialised.
App.Config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="cnn"
connectionString="Persist Security Info=False;
Data Source=localhost;
Initial Catalog=ha;
Integrated Security=SSPI;
Trusted_Connection=TRUE;" />
</connectionStrings>
</configuration>
Thanks