public ActionResult Index(Lead lead) { if (ModelState.IsValid) { //save lead in DB DataWriter.writeLead(lead); return RedirectToAction("Thanks"); } return View(); }
public static void writeLead(Lead lead) { string file = HttpContext.Current.ApplicationInstance.Server.MapPath("~/App_Data"); file += "/LeadCapture.sqlite"; SQLiteConnection m_dbConnection = new SQLiteConnection("Data Source=" + file + ";Version=3;"); m_dbConnection.Open(); //create lead insert statement string sql = "INSERT INTO Leads (firstName, lastName, phoneNumber, zip, email) values ('" + lead.firstName + "', '" + lead.lastName + "', '" + lead.phoneNumber + "', '" + lead.zip + "', '" + lead.email + "')"; SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection); command.ExecuteNonQuery(); }