Jump to content

Having problem filling dataset with sqldataadapter

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
hoser2001

hoser2001

    Programmer

  • Members
  • PipPipPipPip
  • 173 posts
SqlDataAdapter da = new SqlDataAdapter("select * from tblTest", str);
DataSet ds = new DataSet();
da.Fill(ds);
dataGrid1.DataSource = ds;

tblTest has 10 columns. But after I fill it, only one column gets displayed in the datagrid. I put a column count after the fill statement to be sure it wasn't anything up to that point, but as far as I can tell something is going wrong when the datagrid's source is assigned. Any ideas what might be wrong?

#2
Lop

Lop

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,172 posts
Hmm, interesting. Everything looks good.

Here is the code from MSDN

private static DataSet SelectRows(DataSet dataset,

    string connectionString,string queryString) 

{

    using (SqlConnection connection = 

        new SqlConnection(connectionString))

    {

        SqlDataAdapter adapter = new SqlDataAdapter();

        adapter.SelectCommand = new SqlCommand(

            queryString, connection);

        adapter.Fill(dataset);

        return dataset;

    }

}



The way you are filling it may be the problem. Try

dataGrid1.DataSource=ds.Tables["tblTest"];


Let me know if that works or not.

#3
hoser2001

hoser2001

    Programmer

  • Members
  • PipPipPipPip
  • 173 posts
No, still no go... Is it possible I have to use tablestyles or something of the sort?

#4
brackett

brackett

    Programmer

  • Members
  • PipPipPipPip
  • 192 posts
Are you using defined (templated) columns? Do you have AutoCreateColumns = True in the aspx or codebehind?