Advertisement
Guest User

Untitled

a guest
Feb 1st, 2014
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using System.Data;
  8. using System.Data.SqlClient;
  9.  
  10. namespace FitMe
  11. {
  12. public partial class Track : System.Web.UI.Page
  13. {
  14. protected void Page_Load(object sender, EventArgs e)
  15. {
  16.  
  17. }
  18.  
  19. protected void Button1_Click(object sender, EventArgs e)
  20. {
  21. string name = regFoodNameTxt.Text;
  22. int cals = regFoodCalTxt.Text;
  23. int protein = regFoodProteinTxt.Text;
  24. int carbs = regFoodCarbsTxt.Text;
  25. int fat = regFoodFatTxt.Text;
  26. string sqlstring;
  27.  
  28. SqlConnection myConnection = new SqlConnection("Data Source=iskra-laptop\SQLEXPRESS;Initial Catalog=master;Integrated Security=True;Pooling=False");
  29.  
  30. try
  31. {
  32. myConnection.Open();
  33. }
  34. catch(Exception e)
  35. {
  36. Console.WriteLine(e.ToString());
  37. }
  38.  
  39. sqlstring = " INSERT INTO FoodsTB (NAME, CALS, PROTEIN, FAT, CARB) VALUES ('" + name + "','" + cals + "','" + protein + "','" + carbs + "', '" + fat + "')";
  40.  
  41. SqlCommand myCommand = new SqlCommand(sqlstring, myConnection);
  42.  
  43. myCommand.ExecuteNonQuery();
  44.  
  45. try
  46. {
  47. myConnection.Close();
  48. }
  49. catch(Exception e)
  50. {
  51. Console.WriteLine(e.ToString());
  52. }
  53. }
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement