Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to save Grid View Data into SQL DATaABASE
but i dont want that all data save from gridview

just save those data who changing or update in gridview
i share detail in image

Detail

a GRID VIEW
and a Huge Data Show In Grid View
and There is a ComboBox In GridView
i want That if User Change ComboBox Value
so These Rows Only Update in Sql DataBase Because if all data update in SQL so there is huge data
what should i do
..
For Grid View I Am using
DataSet
DataTable
DataRow
----
Click Here To View IMage to Further Explain
Posted
v2

You can do like below...

1. OnRowUpdating event check whether that ComboBox value is changed or not.

  • IF value is changed

    • update the row

  • ELSE

    • don't update



And for checking whether the ComboBox value changed or not, you can have another HiddenField on each GridView Row, which will just store the selected value of ComboBox when GridView is loaded.

And when you will check in the above event, you need to compare the current selected value of ComboBox with the stored selected value in HiddenField.

If they are different, then update the row, otherwise don't update.
 
Share this answer
 
Comments
Abhinav S 4-Jun-13 0:42am    
Correct. My 5.
Thanks a lot Abhinav S... :)
saimm 4-Jun-13 7:14am    
thanks i try this logic
i am not using Event but copy value in hiden column of gridview thanks again
Most Welcome... My pleasure. :)
Glad to know that logic helped you. And good work by you as you implemented it. Thanks...

Regards,
Tadit
Try
           Dim connectionString As String = ConfigurationManager.ConnectionStrings("ConString").ConnectionString
           Dim con As New SqlConnection(connectionString)
           con.Open()

           Dim cmd As New SqlCommand("INSERT INTO BookDetail VALUES(@Printing_Method,@year,@Month,@Faculty,@Course_Code,@Block,@Medium)")
           cmd.CommandType = CommandType.Text
           ' Dim adapFam As New SqlDataAdapter


           For i As Integer = 0 To DataGridView1.Rows.Count - 1
               cmd.Parameters.AddWithValue("@Printing_Method", DataGridView1.Rows(i).Cells(0).Value.ToString())
               cmd.Parameters.AddWithValue("@year", DataGridView1.Rows(i).Cells(1).Value.ToString())
               cmd.Parameters.AddWithValue("@Month", DataGridView1.Rows(i).Cells(2).Value.ToString())
               cmd.Parameters.AddWithValue("@Faculty", DataGridView1.Rows(i).Cells(3).Value.ToString())
               cmd.Parameters.AddWithValue("@Course_Code", DataGridView1.Rows(i).Cells(4).Value.ToString())
               cmd.Parameters.AddWithValue("@Block", DataGridView1.Rows(i).Cells(5).Value.ToString())
               cmd.Parameters.AddWithValue("@Medium", DataGridView1.Rows(i).Cells(6).Value.ToString())
               cmd.Connection = con
               cmd.ExecuteNonQuery()
               'adapFam.InsertCommand.ExecuteNonQuery()

           Next
           con.Close()
           MessageBox.Show("Successfully saved", "Inventory", MessageBoxButtons.OK, MessageBoxIcon.Information)

       Catch ex As Exception
           MsgBox(ex.Message)
       End Try
 
Share this answer
 

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