public void DInsert(Trainee1 t1) { //DataSet ds = new DataSet(); string constr = @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=SNR;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"; using (SqlConnection con = new SqlConnection(constr)) { SqlCommand cmd = new SqlCommand(); try { con.Open(); cmd = new SqlCommand("Insert", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@tid", t1.tid); cmd.Parameters.AddWithValue("@tname", t1.tname); cmd.Parameters.AddWithValue("@location", t1.location); cmd.Parameters.AddWithValue("@techdomain", t1.techdomain); cmd.Parameters.AddWithValue("@startdate", t1.startdate); cmd.CommandText = "insTrainee"; cmd.Connection = con; cmd.CommandType = CommandType.StoredProcedure; SqlDataAdapter sda = new SqlDataAdapter(cmd); sda.Fill(ds); sda.Update(ds); } catch (Exception e) { } } }
protected void Button1_Click(object sender, EventArgs e) { TraineeDataLayer t = new TraineeDataLayer(); Trainee1 t1 = new Trainee1 { tid = int.Parse(TextBox1.Text), tname = TextBox2.Text, location = TextBox3.Text, techdomain = TextBox4.Text, startdate = DateTime.Parse(TextBox5.Text) }; t.DInsert(t1); }