Click here to Skip to main content
14,698,677 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?
Posted
Comments
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
cn.Open()
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 & "'"
cmd.ExecuteNonQuery()
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)
Me.DataTableAdapter.Fill(Me.RecordDataSet.data)
[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 vb.net, not in asp.net 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
sudeshna from bangkok 1-Aug-13 13:47pm
   
My columns name in tables are id,type(nvarchar),qty(int),dt(datetime)
sudeshna from bangkok 1-Aug-13 13:49pm
   
Now please can you help me with code
My project is at the last stage.i need to show to my senior at office
Please all the experts help me.
sudeshna from bangkok 1-Aug-13 13:49pm
   
I request you

Thankx in advance

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.

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