예제 #1
0
        public bool delete(VehicleClass v)
        {
            bool          isSuccess = false;
            SqlConnection conn      = new SqlConnection(connString);

            try
            {
                string     sql = "DELETE FROM VehDetails WHERE VehicleID=@VehicleID";
                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("@VehicleID", v.VehicleID);

                conn.Open();
                int rows = cmd.ExecuteNonQuery();

                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception e)
            {
            }
            finally
            {
                conn.Close();
            }
            return(isSuccess);
        }
예제 #2
0
        //inserting data into database

        public bool insert(VehicleClass v)
        {
            bool          isSuccess = false;
            SqlConnection conn      = new SqlConnection(connString);

            try
            {
                string sql = "INSERT INTO VehDetails (Brand, Model, EngineNo, ChassiNo, ProductionYear, Type, EnteredDate, CustomerID) VALUES ('" + v.Brand + "', '" + v.Model + "', '" + v.EngineNo + "', '" + v.ChassiNo + "', '" + v.ProductionYear + "', '" + v.Type + "', '" + DateTime.Now.ToString("yyyy-MM-dd") + "','" + v.CustomerID + "')";

                SqlCommand cmd = new SqlCommand(sql, conn);

                //cmd.Parameters.AddWithValue("@Brand", v.Brand);
                //cmd.Parameters.AddWithValue("@Model", v.Model);
                //cmd.Parameters.AddWithValue("@EngineNo", v.EngineNo);
                //cmd.Parameters.AddWithValue("@ChassiNo", v.ChassiNo);
                //cmd.Parameters.AddWithValue("@ProductionYear", v.ProductionYear);
                //cmd.Parameters.AddWithValue("@Type", v.Type);
                //cmd.Parameters.AddWithValue("@EnteredDate", DateTime.Now);

                conn.Open();
                int rows = cmd.ExecuteNonQuery();

                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (System.Data.SqlClient.SqlException sqlExceptione)
            {
                System.Windows.Forms.MessageBox.Show(sqlExceptione.Message);
            }
            finally
            {
                conn.Close();
            }
            return(isSuccess);
        }
예제 #3
0
        //update data in database

        public bool update(VehicleClass v)
        {
            bool          isSuccess = false;
            SqlConnection conn      = new SqlConnection(connString);

            try
            {
                string     sql = "UPDATE VehDetails SET Brand='" + v.Brand + "', Model='" + v.Model + "', EngineNo='" + v.EngineNo + "', ChassiNo='" + v.ChassiNo + "', ProductionYear='" + v.ProductionYear + "', Type='" + v.Type + "', EnteredDate='" + v.EnteredDate + "' WHERE VehicleID='" + v.VehicleID + "'";
                SqlCommand cmd = new SqlCommand(sql, conn);

                //cmd.Parameters.AddWithValue("@Name", c.Name);
                //cmd.Parameters.AddWithValue("@NIC", c.NIC);
                //cmd.Parameters.AddWithValue("@Address", c.Address);
                //cmd.Parameters.AddWithValue("@PhoneNumber", c.PhoneNumber);
                //cmd.Parameters.AddWithValue("@EMail", c.EMail);
                //cmd.Parameters.AddWithValue("@Gender", c.Gender);

                conn.Open();
                int rows = cmd.ExecuteNonQuery();

                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception e)
            {
            }
            finally
            {
                conn.Close();
            }
            return(isSuccess);
        }