c#中执行存储过程

来源:互联网 发布:视频日语翻译中文软件 编辑:程序博客网 时间:2024/05/21 21:41

 

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];
}

原创粉丝点击