小弟C#初学者,现在有个问题急待求教解决方法,是C/S,不是B/S的!!例如我数据库的表有这样的结构tb_Test中有3个列,名字,日期,状态输入起始时间到结束时间需要横向显示时间,纵向显示名字,其中对应坐标的单元格显示状态最好还能对相应的状态设置单元格颜色我考虑过用datagridview做,但始终没想出好的动态绑定数据库的方法求教解决方法!!!

解决方案 »

  1.   

    datagridview
      

  2.   


    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Data.SqlClient;namespace WinTest
    {
      public partial class Form1 : Form
      {
      public Form1()
      {
      InitializeComponent();
      }  private void Form1_Load(object sender, EventArgs e)
      {
      using (SqlConnection myCon = new SqlConnection("你的连接字符串"))
      {
      SqlDataAdapter myDa = new SqlDataAdapter("你的查询SQL语句", myCon);
      DataSet myDs = new DataSet();
      myDa.Fill(myDs, "temTable");
      DataGridView1.DataSource = myDs.Tables[0];
      }
      }
      }
    }
      

  3.   


    DataTable dt=New DataTable();
    dt.Columns.add("名称",Typeof(string));
    ...............................
    dt.Rows["名称"]="名称";
      

  4.   

    DataGridView控件用法合集