private void button2_Click(object sender, EventArgs e) { DateTime time = DateTime.Now; string format = "yyyy-MM-dd HH:mm:ss"; masaDurumu = false; kontrol(); SqlCommand cmd = new SqlCommand("select BaslangicSaat from MasaBilgisi where KullaniciAdi='" + kullaniciAdi + "' and MasaNo='" + masaNo + "' and Durum=1", conn); conn.Open(); DateTime baslangic = Convert.ToDateTime(cmd.ExecuteScalar()); // DateTime baslangic = new DateTime(2018,04,30,22,56,00); //Kontrol için. Orjinali üst satırda TimeSpan sonuc = DateTime.Now - baslangic; int dakika = Convert.ToInt32(sonuc.TotalMinutes); decimal fiyat = numericUpDown1.Value / 60; decimal ucret = Convert.ToDecimal(fiyat * dakika); ucret = Convert.ToDecimal(Math.Round(ucret, 2)); String ucret2 = ucret.ToString().Replace(",", "."); lblMasaUcret.Text = (ucret2 + " TL"); conn.Close(); conn.Open(); SqlCommand cmd2 = new SqlCommand("update MasaBilgisi set Ucret = '" + ucret2 + "', Durum=0,BitisSaat='" + time.ToString(format) + "' where KullaniciAdi='" + kullaniciAdi + "' and MasaNo = " + masaNo + "", conn); DataTable dt2 = new DataTable(); SqlDataAdapter da = new SqlDataAdapter(cmd2); da.Fill(dt2); conn.Close(); Masalar masa = (Masalar)Application.OpenForms["Masalar"]; masa.yesilYap(masaNo); }