Hi All,
Iam trying to login with username and password but not succeded .
Let me elobrate what i have done
open vs2010--> new project --....> Mainwindow , taken two text boxes and one login button then
soluton explorer --. add new item ....server based database named DataBaseRajaWPF .mdf and double clicked on mdf file thn opend the wizared went throw the wizard then created table in mdf file , table name MyUsers. the n developed bellow code
private void Button_Click_1(object sender, RoutedEventArgs e)
{
string cs = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=E:\WPF Code\DBDemoRaja_2\DataBaseRajaWPF;Integrated Security=True";
SqlConnection cn = new SqlConnection(cs);
string sql = string.Format("select count(*) from MyUsers where UserName = '{0}' and PWD='{1}'", txtUsername.Text, txtPassword.Password);
SqlCommand cmd = new SqlCommand();
cmd.Connection = cn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = sql;
if (cn.State == ConnectionState.Closed)
cn.Open();
int cnt = int.Parse(cmd.ExecuteScalar().ToString());
cn.Close();
if (cnt > 0)
MessageBox.Show("Valid User...", "Success");
else
MessageBox.Show("Invalid Username or password..", "Error");
App.config
<connectionStrings>
<add name="DBDemoRaja_2.Properties.Settings.DataBaseRajaWPFConnectionString"
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\DataBaseRajaWPF.mdf;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
iam getting bellow error how to solve this please
An attempt to attach an auto-named database for file E:\WPF Code\DBDemoRaja_2\DataBaseRajaWPF failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
Thanks in Advance
Srilatha