コード例 #1
0
        public void EditDriverInformation(drivers driver)
        {
            string connectionString = ConfigurationManager.ConnectionStrings["DBcon"].ConnectionString;

            using (SqlConnection con = new SqlConnection(connectionString))
            {
                string     query = "UPDATE drivers SET driverName=@driverName,NicID=@NicID, DrivingLicenseID=@DrivingLicenseID,driverAge=@driverAge,contactNo=@contactNo,yearsOfExperience=@yearsOfExperience WHERE driverID=@driverID";
                SqlCommand cmd   = new SqlCommand(query, con);

                SqlParameter paramdriverName = new SqlParameter();
                paramdriverName.ParameterName = "@driverName";
                paramdriverName.Value         = driver.driverName;
                cmd.Parameters.Add(paramdriverName);

                SqlParameter paramNicID = new SqlParameter();
                paramNicID.ParameterName = "@NicID";
                paramNicID.Value         = driver.NicID;
                cmd.Parameters.Add(paramNicID);

                SqlParameter paramDrivingLicenseID = new SqlParameter();
                paramDrivingLicenseID.ParameterName = "@DrivingLicenseID";
                paramDrivingLicenseID.Value         = driver.DrivingLicenseID;
                cmd.Parameters.Add(paramDrivingLicenseID);

                SqlParameter paramdriverAge = new SqlParameter();
                paramdriverAge.ParameterName = "@driverAge";
                paramdriverAge.Value         = driver.driverAge;
                cmd.Parameters.Add(paramdriverAge);

                SqlParameter paramcontactNo = new SqlParameter();
                paramcontactNo.ParameterName = "@contactNo";
                paramcontactNo.Value         = driver.contactNo;
                cmd.Parameters.Add(paramcontactNo);

                SqlParameter paramyearsOfExperience = new SqlParameter();
                paramyearsOfExperience.ParameterName = "@yearsOfExperience";
                paramyearsOfExperience.Value         = driver.yearsOfExperience;
                cmd.Parameters.Add(paramyearsOfExperience);

                SqlParameter paramdriverID = new SqlParameter();
                paramdriverID.ParameterName = "@driverID";
                paramdriverID.Value         = driver.driverID;
                cmd.Parameters.Add(paramdriverID);

                con.Open();
                cmd.ExecuteNonQuery();
            }
        }
コード例 #2
0
        public void DeleteDriver(drivers driver)
        {
            string connectionString = ConfigurationManager.ConnectionStrings["DBcon"].ConnectionString;

            using (SqlConnection con = new SqlConnection(connectionString))
            {
                string     query = "DELETE drivers  WHERE driverID=@driverID";
                SqlCommand cmd   = new SqlCommand(query, con);


                SqlParameter paramdriverID = new SqlParameter();
                paramdriverID.ParameterName = "@driverID";
                paramdriverID.Value         = driver.driverID;
                cmd.Parameters.Add(paramdriverID);

                con.Open();
                cmd.ExecuteNonQuery();
            }
        }