Sofari Agali

Sofari Agali

  • 1.9k
  • 182
  • 18.6k

Saving data in localDB

Oct 2 2020 9:06 AM
Hi!
I am facing a problem saving data in a local sql server 2008 database, in fact when I save everything is fine but as soon as I consult the database data there is nothing in it, someone could one help me please, here are my codes 
 
Ma connexion string
  1. class connexion    
  2.     {  
  3.         public static string getconnexion()  
  4.         {  
  5.             return "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\\Database.mdf;Integrated Security=True";  
  6.         }  
  7.     }  
 Class To Add Client:
  1. {  
  2.            SqlConnection con = new SqlConnection(connexion.getconnexion());  
  3.            con.Open();  
  4.            SqlCommand cmd1 = new SqlCommand("Insert into client(num_passport,nom,adresse,phone) values(@num_passport,@nom,@adresse,@phone)", con);  
  5.            // cmd1.CommandType = System.Data.CommandType.StoredProcedure;  
  6.   
  7.            cmd1.Parameters.AddWithValue("@num_passport", num_passport);  
  8.            cmd1.Parameters.AddWithValue("@nom", nom);  
  9.            cmd1.Parameters.AddWithValue("@adresse", adresse);  
  10.            cmd1.Parameters.AddWithValue("@phone", phone);  
  11.            cmd1.ExecuteNonQuery();  
Button Add event:
  1. private void button1_Click(object sender, EventArgs e)  
  2.         {  
  3.             SaisieClient st = new SaisieClient();  
  4.             st.Num_passport = idclt.Text;  
  5.             st.Nom = clt.Text;  
  6.             st.Adresse = adres.Text;  
  7.             st.Phone = Int32.Parse(phone.Text).ToString();  
  8.            st.Saisie();  
 

Answers (5)