Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Data won't save to database, C#

$
0
0
Hi, with your previus help, I managed to get most of the things sorted out. now there is a problem with my DataGridView. When I update row in DataGridView, it stays there until i close the program, so I suppose, changes are only made to loaded DataTable. I searched alot for the solution on the internet, but nothing worked.

Here is the update function (only updating one row at the moment):
void update(int row)
        {
            DataGridViewCell cell = dataGridView2.CurrentCell as DataGridViewCell;
            if (cell.IsInEditMode)
            {
                string query;
                sqlcon.Open();
                query = "update tabelaZaposlenih set ime='" + dataGridView2.Rows[row].Cells[1].EditedFormattedValue + "'";
                sqlcmd = new SqlCommand(query, sqlcon);
                // i added this line afterwards, but no joy...
                sqlcmd.Parameters.AddWithValue("ime", dataGridView2.Rows[row].Cells[1].EditedFormattedValue);
                sqlcmd.ExecuteNonQuery();
                sqlcon.Close();
                MessageBox.Show("Podatki uspešno posodobljeni", "Podatki uporabnika");
            }
        }



What am I doing wrong this time? :) Thanks.

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>