// Insert Problem data into a database public bool User_Data_Insert(User_Data D) { // Create a Default Return bool flag = false; // Step 1 : Connecton to database SqlConnection conn = new SqlConnection(myconnstring); try { // Step 2 : Create a SQL Query to Insert data string sql = "insert into User_Data_Table (Reg_no,Name,Email_Id,Contact_no,Gender,Designation,Problem_Domain) VALUES(@Reg_no,@Name,@Email_Id,@Contact_no,@Gender,@Designation,@Problem_Domain)"; // Step 3 : Create Sql Command using sql and conn SqlCommand cmd = new SqlCommand(sql, conn); // Step 4 : Create Parameters to add data cmd.Parameters.AddWithValue("@Reg_no", D.Reg_no); cmd.Parameters.AddWithValue("@Name", D.Full_name); cmd.Parameters.AddWithValue("@Email_Id", D.Email_id); cmd.Parameters.AddWithValue("@Contact_no", D.Contact); cmd.Parameters.AddWithValue("@Gender", D.Gender); cmd.Parameters.AddWithValue("@Designation", D.Designation); cmd.Parameters.AddWithValue("@Problem_Domain", D.Problem_Domain); // Connection Open Here conn.Open(); int rows = cmd.ExecuteNonQuery(); // If query runs successfully than the value of rows is grater than zero if (rows > 0) { flag = true; } else { flag = false; } } catch (Exception ex) { MessageBox.Show(" Error : " + ex); } finally { conn.Close(); } return(flag); }
// Insert Problem data into a database public bool Problem_Data_Insert(User_Data D) { // Create a Default Return bool flag = false; // Step 1 : Connecton to database SqlConnection conn = new SqlConnection(myconnstring); try { // Step 2 : Create a SQL Query to Insert data string sql = "insert into User_Problem_Data_Table (problem_id, User_Reg_no, Referal_Reg_no, Block, Room_no, Problem, Discription, Status) VALUES (@problem_id, @User_Reg_no, @Referal_Reg_no, @Block, @Room_no, @Problem, @Discription, @Status)"; // Step 3 : Create Sql Command using sql and conn SqlCommand cmd = new SqlCommand(sql, conn); // Step 4 : Create Parameters to add data cmd.Parameters.AddWithValue("@problem_id", Int32.Parse(D.problem_id)); cmd.Parameters.AddWithValue("@User_Reg_no", D.User_Reg_no); cmd.Parameters.AddWithValue("@Referal_Reg_no", D.Referal_Reg_no); cmd.Parameters.AddWithValue("@Block", D.Block); cmd.Parameters.AddWithValue("@Room_no", D.Room_no); cmd.Parameters.AddWithValue("@Problem", D.Problem); cmd.Parameters.AddWithValue("@Discription", D.Discription); cmd.Parameters.AddWithValue("@Status", D.Status); // Connection Open Here conn.Open(); int rows = cmd.ExecuteNonQuery(); // If query runs successfully than the value of rows is grater than zero if (rows > 0) { flag = true; } else { flag = false; } } catch (Exception ex) { MessageBox.Show(" Error : " + ex); } finally { conn.Close(); } return(flag); }