private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
myConnection=new SqlConnection("server=127.0.0.1;uid=sa;pwd=sa;database=qqq;");
strSQL="SELECT fname AS [First Name], lname AS [Last Name FROM Employee";
myCommand=new SqlDataAdapter(strSQL,myConnection);
myCommand.Fill(ds,"Employee");
ds.Tables[0].Columns.Add("No");
DataGrid1.DataSource=ds.Tables["Employee"].DataSet;
for (int i=0;i<ds.Tables[0].Rows.Count;i++)
{
ds.Tables[0].Rows[i]["No"]=i+1;
}
DataGrid1.DataBind();
}
}
但是显示时候结构是No,First Name,Last Name,No,最后这个No怎么去掉,请指导下,谢谢!
{
if(!IsPostBack)
{
myConnection=new SqlConnection("server=127.0.0.1;uid=sa;pwd=sa;database=qqq;");
strSQL="SELECT fname AS [First Name], lname AS [Last Name FROM Employee";
myCommand=new SqlDataAdapter(strSQL,myConnection);
myCommand.Fill(ds,"Employee");
ds.Tables[0].Columns.Add("No");
DataGrid1.DataSource=ds.Tables["Employee"].DataSet;
for (int i=0;i<ds.Tables[0].Rows.Count;i++)
{
ds.Tables[0].Rows[i]["No"]=i+1;
}
DataGrid1.DataBind();
}
}