libdo

Untitled

Sep 21st, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Data.SqlClient;
  10.  
  11. namespace ProjDatabase
  12. {
  13. public partial class Form2 : Form
  14. {
  15. public Form2()
  16. {
  17. InitializeComponent();
  18. }
  19. ////BELOW WILL BE INVOKED IF THE BUTTON "Cancel" is Clicked
  20. //private void btnCancel_Click(object sender, EventArgs e)
  21. //{
  22.  
  23. //}
  24.  
  25.  
  26. //BELOW WILL BE INVOKED IF THE BUTTON "Saving NOT Using DataSet" is Clicked
  27. // private void btnSubmit_Click(object sender, EventArgs e)
  28. // {
  29. // try
  30. // {
  31. // //GET THE DATA IN THE FORM and store them in variables
  32. // string FigureName, Height, Scale, Price, ProductNumber, Manufacturer, iType, ReleaseDate;
  33. // FigureName = txtNameofFigurine.Text.ToString();
  34. // Height = txtHeight.Text.ToString();
  35. // Scale = txtScale.Text.ToString();
  36. // Price = txtPrice.Text.ToString();
  37. // ProductNumber = txtProductNumber.Text.ToString();
  38. // Manufacturer =txtManufacturer.Text.ToString();
  39. // iType = txtiType.Text.ToString();
  40. // ReleaseDate = txtReleaseDate.Text.ToString();
  41.  
  42. // //ACCESS THE DATA SOURCE
  43. // string connString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\marvin\Desktop\FigureSaleDatabase.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
  44. // SqlConnection connStudent = new SqlConnection(connString);
  45. // connStudent.Open();
  46.  
  47. // string sqlInsertStatement = @"Insert into Name (FigureName, Height, Scale, Price, Product Number)
  48. // Values ('" + FigureName + "','" +Height + "', '" + Scale + "', '"
  49. // + Price + "', '" + ProductNumber + "' )";
  50.  
  51. // SqlCommand cmdTxt = new SqlCommand(sqlInsertStatement, connStudent);
  52.  
  53. // cmdTxt.ExecuteNonQuery();
  54. // MessageBox.Show("Saving is done!");
  55.  
  56. // //CLOSE THE DATA SOURCE
  57. // connStudent.Close();
  58. // connStudent.Dispose();
  59. // this.Close(); //CLOSE THE FORM
  60. // }
  61. // catch (Exception exc)
  62. // {
  63. // MessageBox.Show(exc.Message);
  64. // }
  65.  
  66.  
  67. private void btnCancel_Click_1(object sender, EventArgs e)
  68. {
  69. this.Close();
  70. }
  71.  
  72. private void btnSubmit_Click_1(object sender, EventArgs e)
  73. {
  74. try
  75. {
  76. //GET THE DATA IN THE FORM and store them in variables
  77. string FigureName, Height, Scale, Price, ProductNumber, Manufacturer, iType, ReleaseDate;
  78. FigureName = txtNameofFigurine.Text.ToString();
  79. Height = txtHeight.Text.ToString();
  80. Scale = txtScale.Text.ToString();
  81. Price = txtPrice.Text.ToString();
  82. ProductNumber = txtProductNumber.Text.ToString();
  83. Manufacturer = txtManufacturer.Text.ToString();
  84. iType = txtiType.Text.ToString();
  85. ReleaseDate = txtReleaseDate.Text.ToString();
  86.  
  87. //ACCESS THE DATA SOURCE
  88. string connString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\marvin\Desktop\FigureSaleDatabase.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
  89. SqlConnection connStudent = new SqlConnection(connString);
  90. connStudent.Open();
  91.  
  92. string sqlInsertStatement = @"Insert into Name (FigureName, Height, Scale, Price, ProductNumber)
  93. Values ('" + FigureName + "','" + Height + "', '" + Scale + "', '"
  94. + Price + "', '" + ProductNumber + "' )";
  95.  
  96. string sqlInsertStatement1 = @"Insert into Manufacturer (Manufacturer, iType, ReleaseDate, ProductNumber)
  97. Values ('" + Manufacturer + "','" +iType + "', '" + ReleaseDate + "', '"
  98. + ProductNumber + "' )";
  99.  
  100. SqlCommand cmdTxt = new SqlCommand(sqlInsertStatement + sqlInsertStatement1, connStudent);
  101.  
  102. //cmdTxt.ExecuteNonQuery();
  103. MessageBox.Show("Saving is done!");
  104.  
  105. //CLOSE THE DATA SOURCE
  106. connStudent.Close();
  107. connStudent.Dispose();
  108. this.Close(); //CLOSE THE FORM
  109. }
  110. catch (Exception exc)
  111. {
  112. MessageBox.Show(exc.Message);
  113. }
  114. }
  115. }
  116. }
Add Comment
Please, Sign In to add comment