Advertisement
Guest User

Untitled

a guest
Oct 26th, 2014
114
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.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. using System.Data.SqlClient;
  16.  
  17. namespace WpfApplication12
  18. {
  19.     /// <summary>
  20.     /// Interaction logic for MainWindow.xaml
  21.     /// </summary>
  22.     public partial class MainWindow : Window
  23.     {
  24.         SqlConnection myConnection = new SqlConnection("server=localhost; Trusted_Connection=yes; database=stuff");
  25.  
  26.  
  27.         public MainWindow()
  28.         {
  29.             SqlCommand myCommand = new SqlCommand();
  30.  
  31.  
  32.  
  33.             InitializeComponent();
  34.  
  35.             try
  36.             {
  37.                 myConnection.Open();
  38.             }
  39.             catch (Exception e)
  40.             {
  41.                 MessageBox.Show(e.ToString());
  42.             }
  43.             myCommand.Connection = myConnection;
  44.             myCommand.CommandText = "INSERT INTO things (secondcolumn) " +
  45.                         "Values ('string')";
  46.             myCommand.ExecuteNonQuery();
  47.  
  48.             try
  49.             {
  50.                 SqlDataReader myReader = null;
  51.                 SqlCommand myReadCommand = new SqlCommand("select * from things",
  52.                                                          myConnection);
  53.                 myReader = myCommand.ExecuteReader();
  54.                 while (myReader.Read())
  55.                 {
  56.                     MessageBox.Show(myReader["id"].ToString());
  57.                     MessageBox.Show(myReader["secondcolumn"].ToString());
  58.                 }
  59.             }
  60.             catch (Exception e)
  61.             {
  62.                 MessageBox.Show(e.ToString());
  63.             }
  64.         }
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement