You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Bài Giảng Môn Lập Trình Website ASP.Net}Initial Catalog=QLbansach;User ID=sa;Password=");SqlCommand cmd = new SqlCommand();cmd.Connection = cnn;//Biến Commnad thao tác với database bằng câu lệnh//(INSERT, UPDATE, DELETE)cmd.CommandText = "INSERT INTO CHUDE(TenCD) VALUES(N'Văn hóa')";cmd.CommandType = CommandType.Text;cnn.Open();//Thao tác dữ liệu (INSERT, UPDATE, DELETE)//bằng phương thức ExecuteNonQuery.cmd.ExecuteNonQuery();//Xuất kết quả ra WebFormTextBox3.Text = "Thành công!";cnn.Close();}catch (Exception){//Xuất kết quả ra WebFormTextBox3.Text = "Không thành công!";}4. Kết nối, thao tác dữ liệu, sử dụng đối tượng Command với câu lệnh INSERT,UPDATE, DELETE + Truyền tham số.protected void Button4_Click(object sender, EventArgs e){try{//Khai báo và khởi tạo biến ConnectionSqlConnection cnn = new SqlConnection("Data Source=(local);Initial Catalog=QLbansach;User ID=sa;Password=");SqlCommand cmd = new SqlCommand();cmd.Connection = cnn;//Khai báo và khởi tạo tham sốSqlParameter parTenLinhVuc =new SqlParameter("@TENCHUDE", SqlDbType.NVarChar, 50);cmd.CommandText ="INSERT INTO CHUDE VALUES(@TENCHUDE)";cmd.CommandType = CommandType.Text;//Thêm biến tham số cho Commandcmd.Parameters.Add(parTenchude);//Gán giá trị cho biến tham sốparTenLinhVuc.Value = TextBox1.Text;cnn.Open();cmd.ExecuteNonQuery();cnn.Close();lbThongbao.Text = "Thành công!";}catch (Exception){lbThongbao.Text = "Không thành công!";}www.Beenvn.com}Biên sọan: Dương Thành Phết Trang 105