Results 1 to 4 of 4

Thread: DataGrid & DataBind()

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2004
    Posts
    50

    DataGrid & DataBind()

    Hi,

    Why does my DataGrid do not accept DataBind?

    Code:
    .... 
    
    string sCnx = "server=..; uid=..; pwd=..; database=..";
    SqlConnection cnx = new System.Data.SqlClient.SqlConnection(sCnx);
    cnx.Open();
    
    SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
    
    cmd.Connection = cnx;
    cmd.CommandText = "GetInfo";
    cmd.CommandType = CommandType.StoredProcedure;
    
    SqlDataAdapter dataAdapter = new SqlDataAdapter();
    dataAdapter.SelectCommand = cmd;
    
    DataSet dataSet = new DataSet();
    dataAdapter.Fill(dataSet);
    
    dgTest.DataSource = procs.GetProc();
    dgTest.DataBind();
    The error is:
    'System.Windows.Forms.DataGrid' does not contain a definition for 'DataBind'

    How can I fill the DataGrid with the dataSet?

  2. #2
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416

    Re: DataGrid & DataBind()

    are you doing web app's?

    if it's in windows app's no need to put databind.
    VB Code:
    1. DataSet dataSet = new DataSet();
    2. dataAdapter.Fill(dataSet);
    3.  
    4. dgTest.DataSource = dataset;

  3. #3

    Thread Starter
    Member
    Join Date
    Oct 2004
    Posts
    50

    Re: DataGrid & DataBind()

    Ok, thanks. No need to put DataBind...

    It works without, but it shows a +, not the DataGrid. If I push the + it show me the word "Table". Finally if I click the "Table" it shows me the DataGrid. Why? How can I display directly the DataGrid?

  4. #4
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416

    Re: DataGrid & DataBind()

    you must create a datatable to show it directly to the datagrid w/ out clicking the "+" sign.
    like this one.
    VB Code:
    1. DataSet dataSet = new DataSet();
    2. dataSet.Tables.Add(new Datatable("dt"));
    3. dataAdapter.Fill(dataSet.Tables[0]);
    4.  
    5. dgTest.DataSource = dataset;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width