Advertisement
Guest User

Untitled

a guest
Dec 15th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.95 KB | None | 0 0
  1. private void button1_Click(object sender, EventArgs e)
  2.         {
  3.             SqlConnection con = new SqlConnection(@"Data Source=DESKTOP-RHTQCBE;Initial Catalog = Studenci; Integrated Security = True");
  4.            // SqlDataAdapter sda = new SqlDataAdapter("SELECT Role FROM Login WHERE Username= '" + textBox1.Text + "'AND Password = '" + textBox2.Text + "' ", con);
  5.             DataTable dt = new System.Data.DataTable();
  6.             DataRow toInsert = dt.NewRow();
  7.  
  8.             Studenci nowyStudent = new Studenci();
  9.             nowyStudent.ST_Imie = textBox1.Text;
  10.             nowyStudent.ST_Nazwisko = textBox2.Text;
  11.             nowyStudent.ST_Adres = textBox3.Text;
  12.  
  13.             string data = textBox4.Text; // dd-MM-yyyy    
  14.             DateTime d;
  15.             if (DateTime.TryParseExact(data, "dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out d))
  16.             {
  17.                 nowyStudent.ST_Data_urodzenia = d;
  18.             }
  19.  
  20.             decimal nrIndeksu;
  21.             if (Decimal.TryParse(textBox5.Text, out nrIndeksu)){
  22.                 nowyStudent.ST_Nr_indeksu = nrIndeksu;
  23.             }
  24.  
  25.             int nrSpecjalizacji;
  26.             if (int.TryParse(textBox6.Text, out nrSpecjalizacji)) {
  27.                 nowyStudent.ID_Specjalizacji = nrSpecjalizacji;
  28.             }
  29.  
  30.             int nrProjektu;
  31.             if(int.TryParse(textBox7.Text, out nrProjektu))
  32.             {
  33.                 nowyStudent.ID_Projektu = nrProjektu;
  34.             }
  35.  
  36.  
  37.            // db.Studenci.Add(nowyStudent);
  38.             dt.Rows.Add(nowyStudent);
  39.  
  40.             //using method from
  41.             var instance = new Form1("");
  42.             instance.loadData();
  43.  
  44.             //Autor nowy = new Autor();
  45.             //nowy.AUT_Imie = tbxImie.Text;
  46.             //nowy.AUT_Nazwisko = tbxNazwisko.Text;
  47.             //db.Autor.Add(nowy);
  48.             //db.SaveChanges();
  49.             //ZaladujDane();
  50.         }
  51.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement