Advertisement
Guest User

Test for @date

a guest
May 21st, 2012
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.91 KB | None | 0 0
  1. using System;
  2. using System.Drawing;
  3. using System.Data;
  4. using System.Data.SqlClient;
  5. using System.Windows;
  6. using System.Text;
  7. using System.Windows.Forms;
  8.  
  9. public class Form1 : Form {
  10.     private DateTimePicker dtp1;
  11.     private Button commit;
  12.     private TextBox textBox1;
  13.  
  14.     private void Initialize() {
  15.         this.Controls.Add(dtp1 = new DateTimePicker() {
  16.             Name = "dtp1",
  17.             Location = new Point(8,8)
  18.         });
  19.  
  20.         this.Controls.Add(commit = new Button {
  21.            Text = "&Commit to DB",
  22.            Location = new Point(8, 300)
  23.         });
  24.  
  25.         this.Controls.Add(textBox1 = new TextBox {
  26.            ReadOnly = true,
  27.            Location = new Point(8, 32),
  28.            Multiline = true,
  29.            Size = new Size(300, 240),
  30.            Font = new Font("Consolas", 10f)
  31.         });
  32.  
  33.         this.Size = new Size(320, 480);
  34.  
  35.         commit.Click += CommitButton_Click;
  36.     }
  37.  
  38.     private void CommitButton_Click(object sender, EventArgs e) {
  39.         using (var connection = new SqlConnection("**************")) {
  40.             using (var cmd = connection.CreateCommand()) {
  41.             cmd.CommandText = "SELECT @date";
  42.                 cmd.Parameters.AddWithValue("date", dtp1.Value);
  43.                
  44.                 connection.Open();
  45.                 var newDate = (DateTime)cmd.ExecuteScalar();
  46.                
  47.                 StringBuilder b = new StringBuilder();
  48.                 b.AppendLine("dtp1.Value: " + dtp1.Value.ToString("s"));
  49.                 b.AppendLine("newDate...: " + newDate.ToString("s"));
  50.                 b.AppendLine("Done!");
  51.  
  52.                 textBox1.Text = b.ToString();
  53.             }
  54.         }
  55.     }
  56.  
  57.     public Form1() {
  58.         Initialize();
  59.         Text = "Test Form";
  60.     }
  61.  
  62.     public static void Main() {
  63.         Application.EnableVisualStyles();
  64.         Application.DoEvents();
  65.         Application.Run(new Form1());
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement