Exemple #1
0
 private String BuildInsertRidesCommand(Rides rds)
 {
     String command;
     StringBuilder sb = new StringBuilder();
     // use a string builder to create the dynamic string
     String prefix = @"INSERT INTO [Rides]
        ([RideName]
        ,[User]
        ,[RideDes]
        ,[RideType]
        ,[RideDate]
        ,[RideLength]
        ,[RideSource]
        ,[RideDestination]) ";
     sb.AppendFormat("Values('{0}', (select U.[User] from Users U, AspNetUsers A where A.UserName = '******' AND A.Id = U.Id ), '{2}', '{3}' ,'{4}', {5},'{6}','{7}')", rds.RideName, rds.UserName, rds.RideDes, rds.RideType, rds.RideDate, rds.RideLength, rds.RideSource, rds.RideDestination);
     command = prefix + sb.ToString();
     return command;
 }
 public string updateDB(string username, string routename, string ridedate, string roundtrip)
 {
     LogFiles lf = new LogFiles();
     if (DateTime.Now.Day.CompareTo(Convert.ToDateTime(ridedate).Day) < 0 || DateTime.Now.Month.CompareTo(Convert.ToDateTime(ridedate).Month) != 0) { lf.Main("Rides", "The Ride Date:" + ridedate + " Can't be in the future or in a diffetent month "); return "Error"; }
     List<Object> mlist = new List<Object>();
     int return_val = 0;
     DBservices dbs = new DBservices();
     Rides rds = new Rides();
     username = username.Replace("'", "''");
     mlist.Add(rds);
     try
     {
         return_val = dbs.InsertDatabase(mlist,username, routename, ridedate, roundtrip);
     }
     catch (Exception ex)
     {
         string Response = ("Error while trying to INSERT the new Ride to the database " + ex.Message);
         lf.Main("Rides", Response);
         return "Error";
     }
     if (return_val == 0) { return "Error"; }
     return "Success";
 }