public bool themSanBay(SanBay sB) { SqlConnection sqlConnection = createConnection(); try { sqlConnection.Open(); //SqlCommand cmd = new SqlCommand("INSERT INTO SAN_BAY(MaSB,TenSB) VALUES ('" + txtMaSB.Text + "',N'" + txtTenSB.Text + "')", con); string SQL = "INSERT INTO SAN_BAY(MaSB, TenSB) VALUES ('" + sB.MaSB + "', N'" + sB.TenSB + "')"; SqlCommand cmd = new SqlCommand(SQL, sqlConnection); // Query và kiểm tra if (cmd.ExecuteNonQuery() > 0) { return(true); } } catch (Exception e) { throw e; } finally { // Dong ket noi sqlConnection.Close(); } return(false); }
public bool xoaSanBay(SanBay sB) { SqlConnection sqlConnection = createConnection(); try { sqlConnection.Open(); string SQL = "DELETE SAN_BAY WHERE MaSB = '" + sB.MaSB + "'"; SqlCommand cmd = new SqlCommand(SQL, sqlConnection); // Query và kiểm tra if (cmd.ExecuteNonQuery() > 0) { return(true); } } catch (Exception e) { throw e; } finally { // Dong ket noi sqlConnection.Close(); } return(false); }
public DataTable GetDataTimKiemSB(SanBay sB) { SqlConnection sqlConnection = createConnection(); string sql = "SELECT MaSB, TenSB FROM SAN_BAY WHERE (MaSB = '" + sB.MaSB + "') OR (TenSB LIKE N'%" + sB.TenSB + "%')"; SqlCommand cmd = new SqlCommand(sql, sqlConnection); SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sql, sqlConnection); DataSet ds = new DataSet(); sqlDataAdapter.Fill(ds); //SqlCommand cmd = new SqlCommand("SELECT * FROM DOIBONG", sqlConnection); //SqlDataAdapter da = new SqlDataAdapter(cmd); //DataSet ds = new DataSet(); //da.Fill(ds); //DGVHienThi.DataSource = ds.Tables[0]; //DGVHienThi.Refresh(); return(ds.Tables[0]); }