Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have one gridview1 control
I want to update data in database through gridview1
when i click on add button the selected row get converted into edit mode
but when i fire query as
C#
cmd = new SqlCommand("update " + Label7.Text + " set " + ds1.Tables[0].Columns[i].ColumnName + "='" + GridView1.Rows[0].Cells[i].Text + "' where " + ds1.Tables[0].Columns[0].ColumnName + "='" + GridView1.Rows[0].Cells[0].Text + "'", con);


the actual value is not inserted in database ,only null value get added i database
how can i add values in gridview1

Plz suggest me any solution
Posted
Updated 14-May-12 3:47am
v2
Comments
Sandeep Mewara 14-May-12 10:03am    
Not clear. Does that mean, a row is inserted but only null values there? When you DEBUGGED it, workflow was fine and all the values were there. Update query formed is correct?
milind31 15-May-12 4:37am    
correct ...
plz give me soln
milind31 15-May-12 4:43am    
Yes ..
rows get inserted but value is null
and if i use the GridView1.Rows[0].Cells[i].tostring() instead GridView1.Rows[0].Cells[i].text it insert the values in database as System.web.ui.control.cell

1 solution

hi i think u can use typed Dataset that will make it easy.

1 : add database to ur Project
2 : then from Data Sources drag ur table to win form (in Datagridview form).
3 : then in goto Form1.cs (F7) form load delete

C#
private void Form1_Load(object sender, EventArgs e)
        {           
     delete this line>>>>>>>>  this.datos_de_estudiantesTableAdapter.Fill
(this.control_de_EstudiantesDataSet.Datos_de_estudiantes);

}

4 : then use automatic generated code in ur save button click function

C#
private void datos_de_estudiantesBindingNavigatorSaveItem_Click(object sender, EventArgs e)
       { 
Use this code>>>>>>>>>>>>> 
 this.Validate();
 this.datos_de_estudiantesBindingSource.EndEdit();                 this.tableAdapterManager.UpdateAll(this.control_de_EstudiantesDataSet);
 this.datos_de_estudiantesTableAdapter.Fill(this.control_de_EstudiantesDataSet.Datos_de_estudiantes);

       }


5 : hope helping u
 
Share this answer
 
v2
Comments
milind31 15-May-12 4:39am    
My application is web application ..
And there is no availability of DataGridview control..in web form

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900