将存储的数据表加载到datagridview中

时间:2011-09-14 06:19:11

标签: c# sql

如果已经创建了SQL连接,并且创建了一个从Excel工作表中获取输入的数据表,那么如何使用SP将数据表加载到桌面应用程序的datagridview中(Visual Studio 2008,正在使用Sql Server 2005)?

1 个答案:

答案 0 :(得分:0)

试试这个:

DataTable t = new DataTable();//in your case it's filled already like below or any other method

c.Open();
using (SqlCeDataAdapter a = new SqlCeDataAdapter("SELECT CO_COMP_ID as Company_Id,CO_COMP_NAME as Company_Name, CO_ACTIVE as Active_Status, CO_FILE_TYPE as Using_File_Type, CO_DESC as Description  FROM CompRegister", c))
{
     a.Fill(t);
     //dgvCompDet.DataSource = t;
     fnDeselectRow();
  }
 c.Close();

将数据表作为数据源提供给datagrid

dgvCompDet.DataSource = t;