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.Threading.Tasks;
- using System.Windows.Forms;
- using System.Data.SqlClient;
- namespace WindowsFormsApplication1
- {
- public partial class Form1 : Form
- {
- private string connectionString = "Server=VAKHO-PC; Database=TestDB; Integrated Security=true;";
- private SqlConnection con;
- private SqlDataAdapter adapter;
- private DataSet dataSet = null;
- public Form1()
- {
- InitializeComponent();
- }
- private void refreshTable()
- {
- this.dataSet = new DataSet("users");
- adapter.Fill(dataSet, "users");
- dataGridView1.DataSource = dataSet.Tables[0];
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- this.con = new SqlConnection(this.connectionString);
- this.adapter = new SqlDataAdapter("SELECT * FROM dbo.Users", con);
- this.refreshTable();
- try
- {
- con.Open();
- }
- catch (SqlException ex)
- {
- MessageBox.Show(ex.Message, "Sql Exception!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
- }
- finally
- {
- MessageBox.Show(con.State.ToString(), "Sql Exception!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
- con.Close();
- }
- }
- private void button1_Click(object sender, EventArgs e)
- {
- this.refreshTable();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment