Professional Documents
Culture Documents
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TranNgocSon
Console.OutputEncoding = Encoding.UTF8;
//Them();
//Sua();
//Xoa();
Hien();
string connectionString =
ConfigurationManager.ConnectionStrings["db_Shop4Training"].ConnectionString;
cmd.CommandType = CommandType.StoredProcedure;
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
da.Fill(CongDanTable);
if (CongDanTable.Rows.Count == 0)
Console.WriteLine("Chua co du lieu");
else
#region câu 1
newCongDan["PK_iCongdanID"] = 5;
newCongDan["tNgaysinh"] = "2002-05-19";
newCongDan["sCMND"] = 127;
newCongDan["sHokhau"] = "LA";
CongDanTable.Rows.Add(newCongDan);
//
insertCmd.CommandType = CommandType.StoredProcedure;
insertCmd.Parameters.Add("@PK_iCongdanID",
SqlDbType.Int).SourceColumn = "PK_iCongdanID";
insertCmd.Parameters.Add("@sHoten", SqlDbType.NVarChar,
10).SourceColumn = "sHoten";
insertCmd.Parameters.Add("@tNgaysinh",
SqlDbType.Date).SourceColumn = "tNgaysinh";
insertCmd.Parameters.Add("@sCMND",
SqlDbType.Int).SourceColumn = "sCMND";
insertCmd.Parameters.Add("@sHokhau", SqlDbType.NVarChar,
10).SourceColumn = "sHokhau";
//
da.InsertCommand = insertCmd;
DataTable dt = CongDanTable.GetChanges();
da.Update(dt);
if (!dt.HasErrors)
dt.AcceptChanges();
//
#endregion
#region Câu 2
dv.Sort = "PK_iCongdanID";
#endregion
Console.ReadLine();
string connectionString =
ConfigurationManager.ConnectionStrings["db_Shop4Training"].ConnectionString;
cmd.CommandType = CommandType.StoredProcedure;
da.Fill(CongDanTable);
if (CongDanTable.Rows.Count == 0)
Console.WriteLine("Chua co du lieu");
else
#region câu 3
int id = int.Parse(Console.ReadLine());
command.CommandText = UpdateString;
command.Parameters.AddWithValue("@idCongdan", index);
command.Parameters.AddWithValue("@PK_iCongdanID", id);
command.Parameters.AddWithValue("@sHoten", hoten);
command.Parameters.AddWithValue("@tNgaysinh", ngaysinh);
command.Parameters.AddWithValue("@sCMND", cmnd);
command.Parameters.AddWithValue("@sHokhau", hokhau);
cnn.Open();
command.ExecuteNonQuery();
cnn.Close();
#endregion
Console.ReadLine();
string connectionString =
ConfigurationManager.ConnectionStrings["db_Shop4Training"].ConnectionString;
cmd.CommandType = CommandType.StoredProcedure;
da.Fill(CongDanTable);
if (CongDanTable.Rows.Count == 0)
{
Console.WriteLine("Chua co du lieu");
else
#region câu 3
cnn.Open();
command.Parameters.AddWithValue("@idCongdan", index);
command.ExecuteNonQuery();
cnn.Close();
#endregion
Console.ReadLine();
{
string connectionString =
ConfigurationManager.ConnectionStrings["db_Shop4Training"].ConnectionString;
cmd.CommandType = CommandType.StoredProcedure;
da.Fill(CongDanTable);
if (CongDanTable.Rows.Count == 0)
Console.WriteLine("Chua co du lieu");
else
#region câu 3
cnn.Open();
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add(new SqlParameter()
ParameterName = "@id",
SqlDbType = SqlDbType.Int,
Value = index
});
using (SqlDataReader reader = command.ExecuteReader())
while (reader.Read())
var ID = reader["PK_iCongdanID"];
Console.WriteLine($"{ID} \t {Hoten} \t
{Ngaysinh} \t {Cmnd} \t {Hokhau}");
cnn.Close();
#endregion
Console.ReadLine();
1213
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
namespace BTVN_Buoi3
class Program
cnn.Open();
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.CommandText = "themmoi";
int n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Nhap id");
string id = Console.ReadLine();
cmd.Parameters.AddWithValue("ID", id);
Console.WriteLine("Nhap Ho ten");
cmd.Parameters.AddWithValue("Hoten", hoten);
Console.WriteLine("Nhap Thang:");
Console.WriteLine("nHập năm:");
cmd.Parameters.AddWithValue("Ngaysinh", namsinh);
Console.WriteLine("Nhapn CMND");
cmd.Parameters.AddWithValue("CMND", CMND);
Console.WriteLine("Nhap Ho khau");
cmd.Parameters.AddWithValue("Hokhau", Hokhau);
var kq = cmd.ExecuteNonQuery();
if (kq == 1)
else
cnn.Close();
cnn.Open();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "hien";
da.Fill(congdan);
if (congdan.Rows.Count == 0)
{
Console.WriteLine("Chua co du lieu");
else
foreach(DataRow dr in congdan.Rows)
,dr["iCongdanID"]
,dr["sHoten"]
,dr["tNgaysinh"]
,dr["sCMND"]
,dr["sHokhau"]);
Console.ReadLine();
}cnn.Close();
cnn.Open();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "updatetblCongdan";
int ID = Convert.ToInt32(Console.ReadLine());
cmd.Parameters.AddWithValue("ID", ID);
Console.WriteLine("Nhap Ho ten");
cmd.Parameters.AddWithValue("Hoten", hoten);
Console.WriteLine("Nhap Thang:");
Console.WriteLine("nHập năm:");
cmd.Parameters.AddWithValue("Ngaysinh", namsinh);
Console.WriteLine("Nhapn CMND");
cmd.Parameters.AddWithValue("CMND", CMND);
Console.WriteLine("Nhap Ho khau");
cmd.Parameters.AddWithValue("Hokhau", Hokhau);
var kq = cmd.ExecuteNonQuery();
if (kq == 1)
else
cnn.Close();
cnn.Open();
int xoa;
cmd.CommandType = CommandType.Text;
cmd.CommandText = @"DELETE dbo.tblCongdan where iCongdanID=@xoa";
xoa = Convert.ToInt32(Console.ReadLine());
cmd.Parameters.AddWithValue("xoa", xoa);
var kq = cmd.ExecuteNonQuery();
if (kq == 1)
else
cnn.Close();
cnn.Open();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "timkiemtheoTen";
cmd.Parameters.AddWithValue("@Hoten", hoten);
da.Fill(tim);
if(tim.Rows.Count==0)
else
foreach(DataRow dr in tim.Rows)
, dr["iCongdanID"]
, dr["sHoten"]
, dr["tNgaysinh"]
, dr["sCMND"]
, dr["sHokhau"]);
}
}cnn.Close();
//inSert();
hien();
// update();
//Xoa();
timtheoTen();
Console.ReadKey();