Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Data.SqlClient;
- namespace TestADO
- {
- public partial class Form1 : Form
- {
- SqlConnection con = new SqlConnection(@"Server=LAB-418-11-PC\STUDENT; Database=Test_DB; Integrated Security=true; Asynchronous Processing=true;");
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- int id = Convert.ToInt32(textBox1.Text);
- string name = textBox2.Text;
- string surname = textBox3.Text;
- SqlCommand updateCommand = new SqlCommand("UPDATE Users SET name=N'" + name + "', surname=N'" + surname + "' WHERE id=" + id + "; WAITFOR DELAY 0:0:5; " + "UPDATE Users SET name=N'" + name + "', surname=N'" + surname + "' WHERE id=" + id, con);
- con.Open();
- IAsyncResult result = updateCommand.BeginExecuteNonQuery();
- while (!result.IsCompleted)
- {
- label1.Text = DateTime.Now.ToLongTimeString();
- System.Threading.Thread.Sleep(1000);
- }
- updateCommand.EndExecuteNonQuery(result);
- MessageBox.Show("Completed!");
- con.Close();
- }
- private void button2_Click(object sender, EventArgs e)
- {
- string name = textBox2.Text;
- string surname = textBox3.Text;
- SqlCommand insertCommand = new SqlCommand("INSERT INTO Users (name, surname) OUTPUT INSERTED.id VALUES(N'" + name + "', N'" + surname + "')", con);
- con.Open();
- Object obj = insertCommand.ExecuteScalar();
- MessageBox.Show(obj.ToString());
- con.Close();
- }
- private void button3_Click(object sender, EventArgs e)
- {
- SqlCommand procedureCall = new SqlCommand("dbo.averageOfId", con);
- procedureCall.CommandType = CommandType.StoredProcedure;
- con.Open();
- Object output = procedureCall.ExecuteScalar();
- MessageBox.Show(output.ToString());
- con.Close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment