<GridViewColumn Header=”监测时间” DisplayMemberBinding=”{Binding Path=Date}”></GridViewColumn>
代码是这样的
SqlDataAdapter sda;
DataTable dt;
void getData()
{
SqlConnectionStringBuilder connbuilder = new SqlConnectionStringBuilder();
connbuilder.DataSource = @”WIN-9BHO8FF7NNT\QFSQLSERVER”;
connbuilder.UserID = “sa”;
connbuilder.Password = “123456”;
connbuilder.InitialCatalog = “SnakeIsland”;
SqlConnection conn = new SqlConnection(connbuilder.ConnectionString);
sda = new SqlDataAdapter(“select id,nodeID,Date,Airtemp,Airhumidity,Soiltemp,Soilmoisture from tb_bioticenvironment ;”, conn);
SqlCommandBuilder commbuilder = new SqlCommandBuilder(sda);
sda.UpdateCommand = commbuilder.GetUpdateCommand();
dt = new DataTable();
//dt.Columns[“Date”].DataType = Type.GetType(“System.bool”);
sda.AcceptChangesDuringUpdate = true;
sda.Fill(dt);
// for (int i = 0; i < dt.Rows.Count; i++)
//{
// dt.Rows[i][“Date”] = Convert.ToDateTime(dt.Rows[i][“Date”]).ToString(“yyyy-MM-dd “);
//}
//dt.Columns[“Date”].DataType = Type.GetType(“ToShortDateString”);
listView1.ItemsSource = dt.DefaultView;
}
100