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 WFA
- {
- public partial class Form1 : Form
- {
- SqlConnection con = new SqlConnection();
- SqlDataAdapter adapter;
- DataSet ds;
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- con.ConnectionString = "Server=LAB-418-08-PC\\STUDENT; database=TestBase; Integrated Security=true;";
- try
- {
- con.Open();
- SqlCommand command = new SqlCommand("SELECT * FROM Users");
- adapter = new SqlDataAdapter("SELECT * FROM Users", con);
- SqlCommandBuilder commandBuilder = new SqlCommandBuilder(adapter);
- ds = new DataSet();
- adapter.Fill(ds, "c");
- dataGridView1.DataSource = ds.Tables["c"];
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.ToString(), "Exception message");
- }
- finally
- {
- con.Close();
- }
- }
- private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
- {
- dataGridView1.BeginEdit(true);
- }
- private void dataGridView1_CellLeave(object sender, DataGridViewCellEventArgs e)
- {
- dataGridView1.EndEdit();
- adapter.Update(ds, "c");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment