Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Drawing;
- using System.Data;
- using System.Data.SqlClient;
- using System.Windows;
- using System.Text;
- using System.Windows.Forms;
- public class Form1 : Form {
- private DateTimePicker dtp1;
- private Button commit;
- private TextBox textBox1;
- private void Initialize() {
- this.Controls.Add(dtp1 = new DateTimePicker() {
- Name = "dtp1",
- Location = new Point(8,8)
- });
- this.Controls.Add(commit = new Button {
- Text = "&Commit to DB",
- Location = new Point(8, 300)
- });
- this.Controls.Add(textBox1 = new TextBox {
- ReadOnly = true,
- Location = new Point(8, 32),
- Multiline = true,
- Size = new Size(300, 240),
- Font = new Font("Consolas", 10f)
- });
- this.Size = new Size(320, 480);
- commit.Click += CommitButton_Click;
- }
- private void CommitButton_Click(object sender, EventArgs e) {
- using (var connection = new SqlConnection("**************")) {
- using (var cmd = connection.CreateCommand()) {
- cmd.CommandText = "SELECT @date";
- cmd.Parameters.AddWithValue("date", dtp1.Value);
- connection.Open();
- var newDate = (DateTime)cmd.ExecuteScalar();
- StringBuilder b = new StringBuilder();
- b.AppendLine("dtp1.Value: " + dtp1.Value.ToString("s"));
- b.AppendLine("newDate...: " + newDate.ToString("s"));
- b.AppendLine("Done!");
- textBox1.Text = b.ToString();
- }
- }
- }
- public Form1() {
- Initialize();
- Text = "Test Form";
- }
- public static void Main() {
- Application.EnableVisualStyles();
- Application.DoEvents();
- Application.Run(new Form1());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement