I have a form (F1) where user will provide their respective credentials username and password . After a sucessfull login , the controls moves to the Client Form (F2) and display welcome username in a label on it.
Client Form contains:
- labels and textboxes(name, address, function , ...)
- Button Insert
- DataGridView bind to DB (name, address, function ,.., UserId)
Now , I want to insert a Client After filling textboxes, I want to add a Client a show it added by user who's connected.
Ex: if I logged with Username Rose after that add a client, in my datagridView , show me my row of insert added by Rose.
Here is my code of Insert:
- private void button1_Click(object sender, EventArgs e)
- {
- if ( comboBox2.SelectedValue != null && textBox1.Text != string.Empty && textBox2.Text != string.Empty && textBox4.Text != string.Empty)
- {
- string cmdStr = "Insert into Client (idUser,name,address,function,telephone,commentaire)values (@idUser,@name,@,address,@function,@telephone,@commentaire)";
- SqlConnection con = new SqlConnection("Data Source=User-PC\\SQLEXPRESS;Initial Catalog=timar;Integrated Security=True");
- SqlCommand cmd = new SqlCommand(cmdStr, con);
- con.Open();
-
-
- cmd.Parameters.AddWithValue("@idUser",label.Text);
- cmd.Parameters.AddWithValue("@name", (comboBox2.SelectedValue));
- cmd.Parameters.AddWithValue("@,address", textBox1.Text);
- cmd.Parameters.AddWithValue("@function", textBox2.Text);
- cmd.Parameters.AddWithValue("@telephone", textBox4.Text);
- cmd.Parameters.AddWithValue("@commentaire",txtArchive.Text);
-
-
- int LA = cmd.ExecuteNonQuery();
- con.Close();
- MessageBox.Show("Le Client a été ajouter avec succés !","Saisie Rendez-vous", MessageBoxButtons.OK, MessageBoxIcon.Information);
- DisplayData();
- ClearData();
- }
- else
- {
- MessageBox.Show("Vérifier que tous les champs sont remplis !","Erreur",MessageBoxButtons.OK,MessageBoxIcon.Information);
- }
- }
I am not able to figure out how to do this, i am very new to c# and trying to learn.
Thanks in Advance .