|
Rank: Member Groups: Member
Joined: 2/21/2008 Posts: 25
|
Hi,
I want to populate Grid with this method:
SqlConnection Conn = new SqlConnection(clsDataProc.GetConnString()); SqlCommand command = new SqlCommand("select * from abc", Conn); Conn.Open(); Grid1.DataSource = command.ExecuteReader(); Grid1.DataBind();
After execution of this method, grid multiply rows as many as it is in select but no generating any columns. What I did missed?
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
|
|
Rank: Newbie Groups: Member
Joined: 1/3/2010 Posts: 4
|
Hello! I am having the same problem. I tried reading the docs but could not understand what I'm missing. Can I please have some assistance? My C# code to populate grid. In my grid I get the same number of rows that the resultSet returns. The fields just don't get populated. Right now I'm only trying to just get anything shown up. I understand that I need to further define what to put inside the columns but I can't find out how to do this. Any assistance is highly appreciated.
Code: C#
private void UpdateData(int i)
{
createConnection("master");
mySqlCommand = mySqlConnection.CreateCommand();
string sql = "SELECT * FROM Customer";
if (Grid1.Columns[0] != null)
sql = string.Format("{0} {1}", sql, Grid1.Columns[0].OrderByClause);
mySqlCommand.CommandText = sql;
Grid1.DataSource = mySqlCommand.ExecuteReader();
Grid1.DataBind();
closeConnection();
}
Grid definition in asp
Code: HTML/ASPX
<Columns>
<eo:RowNumberColumn>
</eo:RowNumberColumn>
<eo:StaticColumn HeaderText="Customer" DataField="" DataType="String">
</eo:StaticColumn>
<eo:StaticColumn HeaderText="Address" DataField="" DataType="String">
</eo:StaticColumn>
<eo:StaticColumn HeaderText="Week" DataField="" DataType="String">
</eo:StaticColumn>
</Columns>
What am I missing?
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi,
You need to set each column's DataField property.
Thanks
|
|
Rank: Newbie Groups: Member
Joined: 1/3/2010 Posts: 4
|
Hi! Thank you, I tried doing that but in my frustrated attempt I forgot to make sure there were columns in the database that matched the name of the datafield defined. Now it works. May this be of use to anyone with the same problem.
Thank you for your quick reply!
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
You are welcome. Glad that it is working for you now!
|
|