George

George

  • NA
  • 3
  • 0

Update with DatagridView

Aug 13 2010 11:05 AM
Hello !
I want to update database(when I click the button1) with the value who I changed in a DatagridView, but I don't know how:

private void button1_Click(object sender, EventArgs e)
        {
            string connString = @"server = evil\sqlexpress;
                                  Database = Punctaje.mdf;
                                  trusted_connection = True;
                                  AttachDbFileName = C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\Punctaje.mdf;";

            DataGridViewCell cell = this.dataGridView1.CurrentCell; // ?!

         
           
           string sql2 = "UPDATE Studenti SET  Nume='" +cell.Value.ToString()+ "' "; //?!
            SqlConnection conn = null;
            SqlDataReader reader2 = null;
            using (conn = new SqlConnection(connString))
            {
                conn.Open();

               
                SqlCommand cmd2 = new SqlCommand(sql2, conn);
                reader2 = cmd2.ExecuteReader();
                reader2.Close();
            }

        }

Answers (1)