while ( r.Read())
{
DataGrid1.Columns. =  r ["QQ"].ToString();
DataGrid1.Columns =  r ["yy"].ToString(); }

解决方案 »

  1.   

    发错了,应该是这样的
    while ( r.Read())
    {
    string QQ = ( string ) r ["QQ"];
    string yy = ( string ) r ["yy"]; string a = QQ;
    string b = yy; }
    这几句都不用要了。
      

  2.   

    非常谢谢 还有点错误"找不到类型或命名空间名称“myDataGrid”(是否缺少 using 指令或程序集引用?)" 我应该怎样来定义"myDataGrid"
      

  3.   

    protected System.Web.UI.WebControls.DataGrid DataGrid1;改成
    protected System.Web.UI.WebControls.DataGrid myDataGrid; 因为这个是你需要的控件
    public class WebForm1 : System.Web.UI.Page
    {
    protected System.Web.UI.WebControls.RadioButtonList RadioButtonList1;
    protected System.Web.UI.HtmlControls.HtmlGenericControl DIV1;
    protected System.Web.UI.WebControls.DataGrid DataGrid1;
    protected System.Web.UI.HtmlControls.HtmlInputButton Button1;

    private void Page_Load(object sender, System.EventArgs e)
    {

    SqlConnection myConnection = new SqlConnection ( "server =localhost; database = dataone; uid = kily;pwd = 123;");
    SqlCommand sqlComm = new SqlCommand ( "SELECT * FROM name ",myConnection );
    try 

    myConnection.Open(); SqlDataReader r = sqlComm.ExecuteReader( CommandBehavior.CloseConnection );

    myDataGrid.DataSource = r;
                                        myDataGrid.DataBind();//把数据绑定在myDataGrid里
    }
    catch (Exception ex)
    {
    string cc = ex.Message;
    }
    finally 
    {        
                                         r.Close();这个也需要把断口关掉。一定要注意
    myConnection.Close();