суббота, 18 сентября 2010 г.

Урок №3 Вставка данных

                Table table = new Table();
                table.Pole1 = t_pole1.Text;
                table.Pole2 = Convert.ToInt32(numeric_pole2.Value);
                float d = (float)Convert.ToDouble(numericUpDownPole3.Value);
                table.Pole3 = d;
                table.Pole4 =Convert.ToDateTime(monthCalendarPole4.SelectionStart);
                if (radioButton1.Checked == true)
                { table.kernel = radioButton1.Text; }
                else
                { table.kernel = radioButton2.Text; }
                 
                db = new BaseTable();               
                db.Distributions.InsertOnSubmit(table);
                db.SubmitChanges();              


Вставка до двух связных таблиц:



            Client client = new Client();
            client.PIB = t_PIB.Text;
            client.DataConnect=DateTime.Now;
             int IDtaruf = (from p in ds.Tarufs

                                 where p.Name==comboBoxTarif.Text
                                 select Convert.ToInt32(p.IDtaruf)).First();
            client.ID_Tarufa=Convert.ToInt32(IDtaruf);
            ds = new DataClasses1DataContext();
            ds.Clients.InsertOnSubmit(client);
          
            User user = new User();
            user.Client = client;
            user.IDuser =Convert.ToInt32(123);
            user.Login = t_Login.Text;
            user.Password = t_Password.Text;

            ds.Users.InsertOnSubmit(user);
            ds.SubmitChanges();

              

Комментариев нет:

Отправить комментарий