最快从查询中创建数据表的方式?数据表、最快、方式

2023-09-05 23:57:49 作者:回忆趁虚而来

什么是code用最小号线将生成一个数据表此SQL查询?

  SELECT *
FROM [表1]
WHERE([日] @之间date1和@ DATE2)和
      ([字段1]为空或[字段2] IS NULL)
 

解决方案

使用 SqlDataAdapter的填写的DataTable。

  DataTable的DT =新的DataTable();
使用(SqlConnection的yourConnection =新的SqlConnection(ConnectionString的))
{
    的SqlCommand CMD =新的SqlCommand(......你的SQL语句,yourConnection);
    SqlDataAdapter的DA =新的SqlDataAdapter(CMD);
    da.Fill(DT);
}
 
统一 Excel 多个工作表中的数据表格式,怎么设置才更快

使用使用 块以您的SqlConnection。还可以使用参数查询

What is the code with the smallest number of lines that will generate a DataTable from this SQL query?

SELECT * 
FROM [Table1] 
WHERE ([Date] BETWEEN @Date1 AND @Date2) AND 
      ([Field1] IS NULL OR [Field2] IS NULL)

解决方案

Use SqlDataAdapter to fill a DataTable.

DataTable dt = new DataTable();
using (SqlConnection yourConnection = new SqlConnection("connectionstring"))
{
    SqlCommand cmd = new SqlCommand("....your sql statement", yourConnection);
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    da.Fill(dt);
}

use using block with your SqlConnection. Also use Parameterized query