public static SurveyDraft GetSurveyDraft(int DraftID) { SurveyDraft d = new SurveyDraft(DraftID); DraftQuestion dq; string query = "SELECT * FROM qrySurveyDrafts WHERE DraftID = @draftID"; using (SqlDataAdapter sql = new SqlDataAdapter()) using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ISISConnectionString"].ConnectionString)) { conn.Open(); sql.SelectCommand = new SqlCommand(query, conn); sql.SelectCommand.Parameters.AddWithValue("@draftID", DraftID); try { using (SqlDataReader rdr = sql.SelectCommand.ExecuteReader()) { while (rdr.Read()) { dq = new DraftQuestion() { ID = (int)rdr["ID"], qnum = (string)rdr["Qnum"], varname = (string)rdr["VarName"], questionText = (string)rdr["QuestionText"], comment = (string)rdr["Comment"], extra1 = (string)rdr["Extra1"], extra2 = (string)rdr["Extra2"], extra3 = (string)rdr["Extra3"], extra4 = (string)rdr["Extra4"], extra5 = (string)rdr["Extra5"], deleted = (bool)rdr["Deleted"], inserted = (bool)rdr["Inserted"] }; d.Questions.Add(dq); } } } catch (Exception) { } } return(d); }
public static void UpdateSurveyDraftQuestion(DraftQuestion d) { string query = "UPDATE qrySurveyDrafts SET QuestionText = @questionText, Comment=@comment WHERE ID = @id"; using (SqlDataAdapter sql = new SqlDataAdapter()) using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ISISConnectionString"].ConnectionString)) { conn.Open(); sql.UpdateCommand = new SqlCommand(query, conn); sql.UpdateCommand.Parameters.AddWithValue("@id", d.ID); sql.UpdateCommand.Parameters.AddWithValue("@questionText", d.questionText); sql.UpdateCommand.Parameters.AddWithValue("@comment", d.comment); sql.UpdateCommand.ExecuteNonQuery(); } }
public static int InsertDraftQuestion(DraftQuestion dq) { using (SqlDataAdapter sql = new SqlDataAdapter()) using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ISISConnectionString"].ConnectionString)) { conn.Open(); sql.InsertCommand = new SqlCommand("proc_createSurveyDraftQuestion", conn) { CommandType = CommandType.StoredProcedure }; sql.InsertCommand.Parameters.AddWithValue("@DraftID", dq.DraftID); sql.InsertCommand.Parameters.AddWithValue("@SortBy", dq.SortBy); sql.InsertCommand.Parameters.AddWithValue("@Qnum", dq.qnum); sql.InsertCommand.Parameters.AddWithValue("@AltQnum", dq.altqnum); sql.InsertCommand.Parameters.AddWithValue("@VarName", dq.varname); sql.InsertCommand.Parameters.AddWithValue("@QuestionText", dq.questionText); sql.InsertCommand.Parameters.AddWithValue("@Comment", dq.comment); sql.InsertCommand.Parameters.AddWithValue("@Extra1", dq.extra1); sql.InsertCommand.Parameters.AddWithValue("@Extra2", dq.extra2); sql.InsertCommand.Parameters.AddWithValue("@Extra3", dq.extra3); sql.InsertCommand.Parameters.AddWithValue("@Extra4", dq.extra4); sql.InsertCommand.Parameters.AddWithValue("@Extra5", dq.extra5); sql.InsertCommand.Parameters.AddWithValue("@Inserted", dq.inserted); sql.InsertCommand.Parameters.AddWithValue("@Deleted", dq.deleted); try { sql.InsertCommand.ExecuteNonQuery(); } catch (Exception) { return(1); } } return(0); }