Hi all,
I have some following code:
Table dt, in fact, has 5 columns A, B, C, D, E, but I want to display just 3 columns in datagridviews A, B, C with new names A1, B1, C1. And I do not know how to do.
Notice that this can not be done in the designing step because my datasoucre is unknown until application runs. It is got by the following code:
Have you got any suggestion for me?
Thank kiu so much!
I have some following code:
Code:
DataTable dt = m_Data.GetInfo(); GridView1.DataSource = dt; GridView1.DataBind();
Notice that this can not be done in the designing step because my datasoucre is unknown until application runs. It is got by the following code:
Code:
//*******my Data.class*************//
public DataTable GetInfo()
{
DataTable dt = new DataTable();
try
{
// Create command
// Command must use two part names for tables
// SELECT <field> FROM dbo.Table rather than
// SELECT <field> FROM Table
// Query also can not use *, fields must be designated
SqlCommand cmd = new SqlCommand("sp_GetInfo", m_sqlConn);
cmd.CommandType = CommandType.StoredProcedure;
// Open the connection if necessary
if(m_sqlConn.State == ConnectionState.Closed)
m_sqlConn.Open();
// Get the messages
dt.Load(cmd.ExecuteReader(CommandBehavior.CloseConnection));
}
catch (Exception ex)
{
throw ex;
}
return dt;
}
//........................................................................................
//****my page*****//
DataTable dt = m_Data.GetInfo();
GridView1.DataSource = dt;
GridView1.DataBind();
Thank kiu so much!
Comment