I have two forms in my project (Form1 & Form2).
On Form1 I have two textBoxes like "Login" Form where user is asked to enter Username (textboxUsername) & Password (textboxPassword). When user is logged in, Form2 pops up.
Now in Form2 I have a button1 and dataGridView1. When I press button1 I want to show the selected user which I entered in Form1 (textboxUsername)
I want to get that user based on his Username which is saved in SQL Server.
Form2 button1 code:
private void button1_Click(object sender, EventArgs e)
{
string constring = @"Data Source=V-K\;Initial Catalog=ATMKlientet;Integrated Security=True";
SqlConnection conDataBase = new SqlConnection(constring);
SqlCommand cmdDataBase = new SqlCommand(" select * from Clients ;", conDataBase);
try
{
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = cmdDataBase;
dbdataset = new DataTable();
sda.Fill(dbdataset);
BindingSource bSource = new BindingSource();
bSource.DataSource = dbdataset;
dataGridView1.DataSource = bSource;
sda.Update(dbdataset);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
In this case, the part where I want to call Form1 textBoxUsername, in Form2 is:
(" select * from Clients where Username='" + this.textBoxUsername + "';", conDataBase);