SqlDataAdapter  comm= new  SqlDataAdapter(conn,myconn);
DataSet ds=new DataSet();
comm.fill(ds);
DataGrid1.DataSource=ds;
DataGrid1.DataBind();

解决方案 »

  1.   

    private void DataGrid1_Load(object sender, System.EventArgs e)
    {
    string connstr,sql;
    connstr="server=10.0.21.100;uid=sa;pwd=sa;database=OA_TM";
    sql="select * from GM_METHOD_FIELD";
    SqlConnection conn=new  SqlConnection(connstr);
    SqlDataAdapter da=new SqlDataAdapter(sql,conn);
    DataSet ds=new DataSet();
    da.Fill(ds,"GM_METHOD_FIELD");
    DataGrid1.DataSource=ds.Tables["GM_METHOD_FIELD"];
    if(!Page.IsPostBack)
    {
    DataGrid1.DataBind(); 
    }
    }
      

  2.   

    string  conn= "SELECT dbo.T_Employee.C_Name, dbo.T_DfEmployee.C_DepartmentID,   dbo.T_DfEmployee.C_EmpState,  dbo.T_DfEmployee.C_BookId, dbo.T_DfEmployee.C_CheckOrg, dbo.T_DfEmployee.C_CheckDate, dbo.T_DfEmployee.C_WCheckDAte,  dbo.T_DfEmployee.C_ClassFROM dbo.T_Employee INNERJOINdbo.T_DfEmployee ON dbo.T_Employee.C_EmpId = dbo.T_DfEmployee.C_EmpId";string  Strconn="server=prgserver;user id=prg;password=prg;database=aq;";
    SqlConnection myconn=new SqlConnection(Strconn); SqlDataAdapter madp=new SqlDataAdapter(conn,myconn);
    madp.Fill(ds);
    DataGrid1.DataSource=ds.Tables[0].DefaultView;
    DataGrid1.DataBind();
      

  3.   

    DataGrid1.DataSource = comm.ExecuteReader();
    DataGrid1.DataBind();