相关疑难解决方法(0)

在c#中使用临时表

我将excel表读入datagrid.从那里,我已经设法将网格的行读入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 …
Run Code Online (Sandbox Code Playgroud)

c# sql temp-tables

7
推荐指数
2
解决办法
4万
查看次数

标签 统计

c# ×1

sql ×1

temp-tables ×1