using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.BindGrid();
}
private void BindGrid()
{
string constring = @"Data Source=192.168.5.191;Initial Catalog=test;Persist Security Info=True;User ID=sa;Password=P5jc5W39G";
using (SqlConnection con = new SqlConnection(constring))
{
using (SqlCommand cmd = new SqlCommand("SELECT * FROM skv", con))
{
cmd.CommandType = CommandType.Text;
con.Open();
DataTable dt = new DataTable();
dt.Load(cmd.ExecuteReader());
dataGridView1.DataSource = dt;
con.Close();
}
}
}
}
}
public static void SetDoubleBuffered(Control c, bool value)
{
PropertyInfo pi = typeof(Control).GetProperty("DoubleBuffered", BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic);
if (pi != null)
{
pi.SetValue(c, value, null);
}
}
SetDoubleBuffered(dataGridView1, true);