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 ShaikhRank #839 · 2.7K reputationPosted Nov 9, 2011, 5:50 AM EST
Javeed M ShaikhRank #839 · 2.7K reputationPosted Nov 8, 2011, 9:25 AM EST
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
}
L Van43 reputationPosted Nov 8, 2011, 9:35 AM EST
string
username = dataSet.Tables[0].Rows[0]["FirstName"].ToString() + " " + dataSet.Tables[0].Rows[0]["LastName"].ToString();Javeed M ShaikhRank #839 · 2.7K reputationPosted Nov 8, 2011, 9:36 AM EST
L Van43 reputationPosted Nov 8, 2011, 9:49 AM EST
Javeed M ShaikhRank #839 · 2.7K reputationPosted Nov 8, 2011, 9:56 AM EST
L Van43 reputationPosted Nov 8, 2011, 10:20 AM EST
L Van43 reputationPosted Nov 8, 2011, 2:40 PM EST
Javeed M ShaikhRank #839 · 2.7K reputationPosted Nov 8, 2011, 2:46 PM EST
L Van43 reputationPosted Nov 8, 2011, 2:48 PM EST
Javeed M ShaikhRank #839 · 2.7K reputationPosted Nov 8, 2011, 4:36 PM EST
L Van43 reputationPosted Nov 9, 2011, 5:07 AM EST
Javeed M ShaikhRank #839 · 2.7K reputationPosted Nov 9, 2011, 5:15 AM EST
L Van43 reputationPosted Nov 9, 2011, 7:14 AM EST
Javeed M ShaikhRank #839 · 2.7K reputationPosted Nov 9, 2011, 7:53 AM EST
Happy Coding :)
L Van43 reputationPosted Nov 9, 2011, 9:28 AM EST
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 ShaikhRank #839 · 2.7K reputationPosted Nov 9, 2011, 9:32 AM EST
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 Van43 reputationPosted Nov 9, 2011, 2:26 PM EST
Javeed M ShaikhRank #839 · 2.7K reputationPosted Nov 9, 2011, 3:48 PM EST