//Inserting Data Into DataBAse public bool InsertJob(assignJobclass c) { bool IsSuccess = false; //step1:connect database SqlConnection conn = new SqlConnection(mynewconnstring); try { string sql = "INSERT INTO jobPred(vehicleNo, jobOne, jobTwo, jobThree, predictPrice,date)VALUES(@vehicleNo, @jobOne, @jobTwo, @jobThree, @predictPrice, @date)"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@vehicleNo", c.Id); cmd.Parameters.AddWithValue("@jobOne", c.jobOne); cmd.Parameters.AddWithValue("@jobTwo", c.jobTwo); cmd.Parameters.AddWithValue("@jobThree", c.jobThree); cmd.Parameters.AddWithValue("@predictPrice", c.predictPrice); cmd.Parameters.AddWithValue("@date", DateTime.Now); //connection open here conn.Open(); int rows = cmd.ExecuteNonQuery(); if (rows > 0) { IsSuccess = true; } else { IsSuccess = false; } } catch (Exception ex) { } finally { conn.Close(); } return(IsSuccess); }
//Update Method public bool Update(assignJobclass c) { bool isSuccess = false; SqlConnection conn = new SqlConnection(mynewconnstring); try { string sql = "UPDATE jobPred SET jobStatus=@jobStatus Where Id=@Id"; //Creating SQL command SqlCommand cmd = new SqlCommand(sql, conn); //Set Parameters cmd.Parameters.AddWithValue("@jobStatus", c.jobStatus); cmd.Parameters.AddWithValue("@Id", c.Id); conn.Open(); int rows = cmd.ExecuteNonQuery(); if (rows > 0) { isSuccess = true; } else { isSuccess = false; } } catch (Exception ex) { } finally { conn.Close(); } return(isSuccess); }