Jes Sie

Jes Sie

  • 742
  • 1.2k
  • 282.1k

Passing 2 parameters but only 1 from sql server DB

Mar 28 2017 3:51 AM
Is it possible to pass 2 parameters in web application but only 1 parameter comes from sql server db? The other parameter comes from a pre set dropdownlist. If it's possible, how to do it? This is what I have in mind but not sure if it is correct.
  1. public static List<CompulsoryTable> GetCompulsoryCoverage(string vehicleType, string Option)  
  2.        {  
  3.            List<CompulsoryTable> getVehicleType = new List<CompulsoryTable>();  
  4.            using (SqlConnection con = DBConnection.GetDbCon())  
  5.            {  
  6.                SqlCommand cmd = new SqlCommand("select * from tblCompulsoryTable where VehicleType = @VehicleType", con);  
  7.                cmd.CommandType = CommandType.Text;  
  8.                cmd.Parameters.AddWithValue("@VehicleType", vehicleType);  
  9.                cmd.Parameters.AddWithValue("@CompulsoryOptions", Option);  
  10.                con.Open();  
  11.   
  12.                SqlDataReader rdr = cmd.ExecuteReader();  
  13.                while (rdr.Read())  
  14.                {  
  15.                    CompulsoryTable Vehicles = new CompulsoryTable();  
  16.                    Vehicles.VehicleType = rdr["VehicleType"].ToString();  
  17.                    getVehicleType.Add(Vehicles);  
  18.                }  
  19.            }  
  20.            return getVehicleType;  
  21.        }  
 

Answers (4)