using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
namespace DataAdapter_14._14
{
class Program
{
static void Main(string[] args)
{
SqlConnection cnn = new SqlConnection("server=.;uid=sa;pwd=system;database=E_TestData");
try
{
cnn.Open();
SqlDataAdapter sda = new SqlDataAdapter(@"select * from TDATA WHERE Date_Time BETWEEN '2018/02/01' AND '2018/02/28'", cnn);
DataSet ds = new DataSet();
sda.Fill(ds, "TestData");
Console.WriteLine("测试数据输出:");
OutValues(ds);
Console.ReadKey();
}
catch(Exception ex)
{
Console.WriteLine(ex.Message.ToString());
}
finally
{
cnn.Close();
}
}
public static void OutValues(DataSet ds)
{
Console.Write("数据集名称{0}",ds.DataSetName);
foreach(DataTable dt1 in ds.Tables)
{
int n=dt1.Rows.Count;
Console.WriteLine("数据表名称{0},{1}行", dt1.TableName,n);
Console.ReadKey();
foreach(DataRow dr1 in dt1.Rows)
{
foreach(DataColumn dc1 in dt1.Columns)
{
Console.Write(dr1[dc1]+"\t");
}
Console.WriteLine();
}
}
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
namespace DataAdapter_14._14
{
class Program
{
static void Main(string[] args)
{
SqlConnection cnn = new SqlConnection("server=.;uid=sa;pwd=system;database=E_TestData");
try
{
cnn.Open();
SqlDataAdapter sda = new SqlDataAdapter(@"select * from TDATA WHERE Date_Time BETWEEN '2018/02/01' AND '2018/02/28'", cnn);
DataSet ds = new DataSet();
sda.Fill(ds, "TestData");
Console.WriteLine("测试数据输出:");
OutValues(ds);
Console.ReadKey();
}
catch(Exception ex)
{
Console.WriteLine(ex.Message.ToString());
}
finally
{
cnn.Close();
}
}
public static void OutValues(DataSet ds)
{
Console.Write("数据集名称{0}",ds.DataSetName);
foreach(DataTable dt1 in ds.Tables)
{
int n=dt1.Rows.Count;
Console.WriteLine("数据表名称{0},{1}行", dt1.TableName,n);
Console.ReadKey();
foreach(DataRow dr1 in dt1.Rows)
{
foreach(DataColumn dc1 in dt1.Columns)
{
Console.Write(dr1[dc1]+"\t");
}
Console.WriteLine();
}
}
}
}
}