Click here to Skip to main content
15,946,074 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have 1 table name data.

in my program, data insertion is working fine. i am showing the database details in datagridview also.this also working fine.

but when my datagridview is showing the details of the values inserted ,there i want to edit/update changes in cell and then that i want to update it in database.

suppose i have columns as name address phone_no
raju bb 98657900
sss cc 88920000

now if i click on any one of the cell in datagridview and make changes then that cell should be updated in database.

how do i do it?

i am new in datagridview concept.

can anyone help me?
sudeshna from bangkok 1-Aug-13 13:27pm    
Dim cn As New SqlConnection("Data Source=.\INSTANCE;initial catalog=record;user=sa;password=gariahat")
Dim da As New SqlDataAdapter
Dim cmd As New SqlCommand
Dim myindex As Integer
Dim myid As Integer
Dim fn As String

myindex = DataDataGridView.CurrentRow.Index
myid = DataDataGridView.Item(0, myindex).Value
fn = DataDataGridView.Item(1, myindex).Value
cmd.Connection = cn
cmd.CommandText = "Update data set " & "type = '" & ComboBox1.Text & "', " & "shape='" & TextBox3.Text & " '," & "size='" & TextBox4.Text & " '," & "place='" & TextBox5.Text & " ' ," & "weight='" & TextBox6.Text & " ', " & "dt = '" & Format(CDate(DateTimePicker1.Value), "MM/dd/yyyy") & "'" & "Where lot_no = '" & TextBox1.Text & "'"
MsgBox("Data successfully updated", MsgBoxStyle.Information)
Me.DataTableAdapter.Insert(TextBox1.Text, ComboBox1.Text, TextBox3.Text, TextBox4.Text, TextBox5.Text, Convert.ToDouble(TextBox6.Text), DateTimePicker1.Value)
[no name] 1-Aug-13 13:33pm    
1. Use the "Improve question" widget to post your code.
2. Format your code so that it is readable.
3. Get rid of the SQL injection attack waiting to happen code and use parameterized queries.
4. Give us something more to work with than "it's not working".
sudeshna from bangkok 1-Aug-13 13:28pm    
this is my code. but i know its wrong,its not working.

can anyone help me with code in, not in or c# or any other language.
joshrduncan2012 1-Aug-13 13:35pm    
Can you tell us why it isn't working?
sudeshna from bangkok 1-Aug-13 13:42pm    
It is telling conversion from string to double nt posible.i used convert.todouble function also but stil nt working

If you want to update on cell's value change, then you need to handle the [MSDN] DataGridView.CellValueChanged Event[^]. In that event, update your Database tables.

And the Error you mentioned about Conversion to Double from String should not ideally happen if the string is in correct format.

Refer - [MSDN] Convert.ToDouble Method (String)[^]. There are examples. So, make sure you are providing the correct dtring to convert.
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