As I stated before I put it in debug and get a row back from my sql statement. The username gets loaded properly. When I tried to load the textblock is when I get the error.
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
{
Login_WPF/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class Login : Window{
{
InitializeComponent();
}
{
{
errormessage.Text =
textBoxEmail.Focus();
}
{
errormessage.Text =
textBoxEmail.Select(0, textBoxEmail.Text.Length);
textBoxEmail.Focus();
}
public Login()Registration registration = new Registration();Welcome welcome = new Welcome();private void button1_Click(object sender, RoutedEventArgs e)if (textBoxEmail.Text.Length == 0)"Enter an email.";else if (!Regex.IsMatch(textBoxEmail.Text, @"^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"))"Enter a valid email.";else{
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();
}
else{
errormessage.Text =
}
con.Close();
}
}
{
registration.Show();
Close();
}
}
}
"Sorry! Please enter existing emailid/password.";private void buttonRegister_Click(object sender, RoutedEventArgs e)