Here is the code. My table name is Users in my database.
using
System;using
System.Collections.Generic;using
System.Linq;using
System.Text;using
System.Windows;using
System.Windows.Controls;using
System.Windows.Data;using
System.Windows.Documents;using
System.Windows.Input;using
System.Windows.Media;using
System.Windows.Media.Imaging;using
System.Windows.Navigation;using
System.Windows.Shapes;using
System.Data;using
System.Data.SqlClient;using
System.Text.RegularExpressions;namespace
{
{
{
InitializeComponent();
}
{
{
errormessage.Text =
textBoxEmail.Focus();
}
{
errormessage.Text =
textBoxEmail.Select(0, textBoxEmail.Text.Length);
textBoxEmail.Focus();
}
{
con.Open();
cmd.CommandType =
adapter.SelectCommand = cmd;
adapter.Fill(dataSet);
{
welcome.TextBlockName.Text = username;
string email = textBoxEmail.Text;string password = passwordBox1.Password;SqlConnection con = new SqlConnection(@"Data Source=.\sqlexpress;Initial Catalog=Customer;Integrated Security=True;Pooling=False");SqlCommand cmd = new SqlCommand("Select * from Users where Email='" + email + "' and Password='" + password + "'", con);CommandType.Text;SqlDataAdapter adapter = new SqlDataAdapter();DataSet dataSet = new DataSet();if (dataSet.Tables[0].Rows.Count > 0)string username = dataSet.Tables[0].Rows[0]["FirstName"].ToString() + " " + dataSet.Tables[0].Rows[0]["LastName"].ToString(); //Sending value from one form to another form.welcome.Show();
Close();
}
{
errormessage.Text =
}
con.Close();
}
}
{
registration.Show();
Close();
}
}
}
"Sorry! Please enter existing emailid/password.";private void buttonRegister_Click(object sender, RoutedEventArgs e)
Javeed M ShaikhPosted Nov 9, 2011, 10:50 AM
Javeed M ShaikhPosted Nov 9, 2011, 8:48 PM
L VanPosted Nov 9, 2011, 7:26 PM
Javeed M ShaikhPosted Nov 9, 2011, 2:32 PM
Please post this is as a new question in the post so it is easier for others to find solution to any questions they are looking for as well as keep the number of replies shorter.
L VanPosted Nov 9, 2011, 2:28 PM
I want to take this application further so I can continue to learn. Lets say I wanted to show another window instead of the "welcome" window. So when login is clicked, instead of showing the welcome window, I wanted to show another window lets say to add customer information. So instead of showing welcome, I show "customer information" and then do the code behind to handle all the editing of the data they input, writing the new records to the database and so on? Is that how I'd do it and is that the way to do it?
Javeed M ShaikhPosted Nov 9, 2011, 12:53 PM
Happy Coding :)
L VanPosted Nov 9, 2011, 12:14 PM
Javeed M ShaikhPosted Nov 9, 2011, 10:15 AM
L VanPosted Nov 9, 2011, 10:07 AM
Javeed M ShaikhPosted Nov 8, 2011, 9:36 PM
L VanPosted Nov 8, 2011, 7:48 PM
Javeed M ShaikhPosted Nov 8, 2011, 7:46 PM
L VanPosted Nov 8, 2011, 7:40 PM
L VanPosted Nov 8, 2011, 3:20 PM
Javeed M ShaikhPosted Nov 8, 2011, 2:56 PM
L VanPosted Nov 8, 2011, 2:49 PM
Javeed M ShaikhPosted Nov 8, 2011, 2:36 PM
L VanPosted Nov 8, 2011, 2:35 PM
string
username = dataSet.Tables[0].Rows[0]["FirstName"].ToString() + " " + dataSet.Tables[0].Rows[0]["LastName"].ToString();Javeed M ShaikhPosted Nov 8, 2011, 2:25 PM
I see you have posted your code here, i see that you have not declared username variable. You are trying to assign a variable to the textblock which is not declared and assigned a value.
you should do this:
if (dataSet.Tables[0].Rows.Count > 0)
{
string username = dataSet.Tables[0].Rows[0]["FirstName"].ToString() + " " + dataSet.Tables[0].Rows[0]["FirstName"].ToString() ;
welcome.TextBlockName.Text = username;
...
...
// other code
}