/// <summary> /// 添加数据 /// </summary> /// <param name="car"></param> public void InsertAuto(NewCar car) { string sql = string.Format("Insert Into Inventory" + "(CarID, Make, Color, PetName) Values" + "(@CarID, @Make, @Color, @PetName)"); using (SqlCommand cmd = new SqlCommand(sql, sqlcn)) { SqlParameter param = new SqlParameter(); param.ParameterName = "@CarID"; param.Value = car.CarID; param.SqlDbType = SqlDbType.Int; cmd.Parameters.Add(param); param = new SqlParameter(); param.ParameterName = "@Make"; param.Value = car.Make; param.SqlDbType = SqlDbType.Char; cmd.Parameters.Add(param); param = new SqlParameter(); param.ParameterName = "@Color"; param.Value = car.Color; param.SqlDbType = SqlDbType.Char; cmd.Parameters.Add(param); param = new SqlParameter(); param.ParameterName = "@PetName"; param.Value = car.PetName; param.SqlDbType = SqlDbType.Char; cmd.Parameters.Add(param); //增加命令 cmd.ExecuteNonQuery(); } }
private static void InsertNewCar(InventoryDAL invDAL) { // First get the user data. int newCarID; string newCarColor, newCarMake, newCarPetName; Console.Write("Enter Car ID: "); newCarID = int.Parse(Console.ReadLine()); Console.Write("Enter Car Color: "); newCarColor = Console.ReadLine(); Console.Write("Enter Car Make: "); newCarMake = Console.ReadLine(); Console.Write("Enter Pet Name: "); newCarPetName = Console.ReadLine(); // Now pass to data access library. // invDAL.InsertAuto(newCarID, newCarColor, newCarMake, newCarPetName); NewCar c = new NewCar { CarID = newCarID, Color = newCarColor, Make = newCarMake, PetName = newCarPetName }; invDAL.InsertAuto(c); }
static void Main(string[] args) { string cnStr = ConfigurationManager.ConnectionStrings["AutoLotSqlProvider"].ConnectionString; // Console.WriteLine(dp); Console.WriteLine(cnStr); InventoryDAL invDAL = new InventoryDAL(); invDAL.OpenConnection(cnStr); try { DeleteCar(invDAL, 44); NewCar c = new NewCar { CarID = 44, Color = "Yellow", Make = "FIAT", PetName = "Bąbel" }; InsertNewCar(invDAL, c); UpdateCarPetName(invDAL, 44, "Bombel"); ListInventoryAsTable(invDAL); ListInventoryAsList(invDAL); LookupPetName(invDAL, 44); DeleteCar(invDAL, 44); } finally { invDAL.CloseConnection(); } Console.ReadLine(); }
public void InsertAuto(NewCar car) { string sql = string.Format("Insert Into Inventory" + "(CarID, Make, Color, PetName) Values" + "('{0}','{1}','{2}','{3}')", car.CarID, car.Make, car.Color, car.PetName); using (SqlCommand cmd = new SqlCommand(sql, this.sqlCn)) { cmd.ExecuteNonQuery(); } }
public void InsertAuto(NewCar car) { string sql = string.Format("INSERT INTO Inventory1 (CarID, Make, Color, PetName)" + "VALUES ('{0}', '{1}', '{2}', {3})", car.CarID, car.Make, car.Color, car.PetName); using (SqlCommand cmd = new SqlCommand(sql, this.sqlCn)) { cmd.ExecuteNonQuery(); } }
public void InsertAuto(NewCar car) { // Format and execute SQL statement. string sql = string.Format("Insert Into Inventory" + "(CarID, Make, Color, PetName) Values" + "('{0}', '{1}', '{2}', '{3}')", car.CarID, car.Make, car.Color, car.PetName); // Execute using our connection. using (SqlCommand cmd = new SqlCommand(sql, this.sqlCn)) { cmd.ExecuteNonQuery(); } }
public void InsertAuto(NewCar car) { // Сформировать SQL-оператор string sql = string.Format("Insert into Inventory" + "(CarID, Make, Color, PetName) Values" + "('{0}', '{1}', '{2}', '{3}')", car.CarID, car.Make, car.Color, car.PetName); // Выполнить SQL оператор с применением нашего подключения using (SqlCommand cmd = new SqlCommand(sql, this.sqlCn)) { cmd.ExecuteNonQuery(); } }
public void InsertAuto(NewCar car) { // Format and execute SQL statement. string sql = string.Format("Insert Into Inventory" + "(CarID, Make, Color, PetName) Values" + "('{0}', '{1}', '{2}', '{3}')", car.CarID, car.Make, car.Color, car.PetName); // Execute using our connection. using (SqlCommand cmd = new SqlCommand(sql, this.sqlCN)) { cmd.ExecuteNonQuery(); } }
static void InsertNewCar(InventoryDAL invDal, NewCar c) { invDal.InsertAuto(c); }
public void InsertAuto(NewCar car) { InsertAuto(car.CarID, car.Color, car.Make, car.PetName); }
public void InsertAuto(NewCar car) { string sql = String.Format("insert into inventory (Make, Color, PetName) Values ('{0}','{1}','{2}')", car.Make, car.Color, car.PetName); using (SqlCommand sqlcmd = new SqlCommand(sql, sqlCn)) { sqlcmd.ExecuteNonQuery(); } }