private void button1_Click(object sender, EventArgs e)
{
string strsql = "SELECT id,name FROM [DepartmentData] group by id,name ";
SqlConnectionStringBuilder CSB = new SqlConnectionStringBuilder();
CSB.DataSource = @"PC003/SQLEXPRESS";
CSB.InitialCatalog = "PCMIS";
CSB.IntegratedSecurity = false;
CSB.UserID = "sa";
CSB.Password = "Ayz179@";
DataSet ds = new DataSet();
try
{
using (SqlConnection cn = new SqlConnection(CSB.ConnectionString))
{
SqlDataAdapter Sda = new SqlDataAdapter(strsql, cn);
Sda.Fill(ds);
}
}
catch
{
if (ds.Tables.Count < 1) ds.Tables.Add(new DataTable());
}
dataGridView1.DataSource = ds.Tables[0];
}