简体   繁体   中英

Loading a stored datatable into a datagridview

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

try this :

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();

Give data table as data source to datagrid

dgvCompDet.DataSource = t;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM