c# - datagridview not update in new table -


hello guys have problem in save of information of absence in form of absence had added datagridview , in there add tow columns combobox form 1 start time of absence , other end time in datagridview when click in bottom of "show" add name , id of each student table named "etudiant" , there datetimepicker in corner out of datagridview need when user choose time of absence , date of each student , click in bottom "save" have saved in other table called "absence" , try , there error please mee it's baccalaureate project :)

private void button2_click(object sender, eventargs e)     { // open connection using connection string.         sqlconnection con = new sqlconnection(@"data source=win-6q836p8jq1c\oby;initial catalog=etudiant;integrated security=true");         con.open();         string sqlquery = "insert abscence (cin,heure_debut,heure_fin,date)";         sqlquery += "values ('cin', 'heure_debut', 'heure_fin', 'date')";             // insert sql table. executenonquery best inserts.             using (sqlcommand com = new sqlcommand(sqlquery, con))             {                 (int = 0; < datagridview1.rows.count; i++)                 {                     com.parameters.addwithvalue("cin", datagridview1.rows[i].cells["cin"].value);                     com.parameters.addwithvalue("heure_debut", datagridview1.rows[i].cells["column1"].value);                     com.parameters.addwithvalue("heure_fin",datagridview1.rows[i].cells["column2"].value);                     com.parameters.addwithvalue("date", datetimepicker1.text);                    }                 com.executenonquery();                 com.parameters.clear();                 con.close();             }         }     } 

please make sure values entering going insert's.

private void button2_click(object sender, eventargs e) { // open connection using connection string.     sqlconnection con = new sqlconnection(@"data source=win-6q836p8jq1c\oby;initial catalog=etudiant;integrated security=true");     con.open();     string sqlquery = "insert abscence (cin,heure_debut,heure_fin,date)";     sqlquery += "values (@cin, @heure_debut, @heure_fin, @date)";          // insert sql table. executenonquery best inserts.         using (sqlcommand com = new sqlcommand(sqlquery, con))         {             (int = 0; < datagridview1.rows.count; i++)             {                 com.parameters.addwithvalue("@cin", datagridview1.rows[i].cells["cin"].value);                 com.parameters.addwithvalue("@heure_debut", datagridview1.rows[i].cells["column1"].value);                 com.parameters.addwithvalue("@heure_fin",datagridview1.rows[i].cells["column2"].value);                 com.parameters.addwithvalue("@date", datetimepicker1.texttostring("yyyy-mm-dd");                }             com.executenonquery();             com.parameters.clear();             con.close();         }     } } 

Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -