我将 excel 表读入数据网格。从那里,我设法将网格的行读入 DataTable 对象。DataTable 对象具有数据,因为当我将网格的数据源与该表对象相等时,网格被填充。
我的问题:我想使用表对象并使用 SQL 服务器操作它的值,(即我想将它存储为临时表并使用 C# 代码中的 SQL 查询来操作它,我希望它返回不同的结果 inte一个网格。(我不知道如何在 C# 中使用临时表)
这是单击按钮时要执行的代码....
SqlConnection conn = new SqlConnection("server = localhost;integrated security = SSPI");
//is connection string incorrect?
SqlCommand cmd = new SqlCommand();
//!!The method ConvertFPSheetDataTable Returns a DataTable object//
cmd.Parameters.AddWithValue("#table",ConvertFPSheetDataTable(12,false,fpSpread2_Sheet1));
//I am trying to create temporary table
//Here , I do a query
cmd.CommandText = "Select col1,col2,SUM(col7) From #table group by col1,col2 Drop #table";
SqlDataAdapter da = new SqlDataAdapter(cmd.CommandText,conn);
DataTable dt = new DataTable();
da.Fill(dt); ***// I get an error here 'Invalid object name '#table'.'***
fpDataSet_Sheet1.DataSource = dt;
//**NOTE:** fpDataSet_Sheet1 is the grid control