ASP 中 怎么把两张表的类型隐形转化为同一类
展开全部
前端:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" >
<Columns>
<asp:BoundField DataField="Name" HeaderText="姓名" />
<asp:BoundField DataField="PersonTypeName" HeaderText="人员类型名称" />
</Columns>
</asp:GridView>
后端:
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=DB;User ID=sa;password=1;");
SqlCommand cmd = new SqlCommand("select Person.Name,PersonType.Name as PersonTypeName from PersonType,Person
where PersonType.ID = Person.PersonTypeID", con);
SqlDataAdapter sda = new SqlDataAdapter();
DataSet ds = new DataSet();
sda.SelectCommand = cmd;
sda.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" >
<Columns>
<asp:BoundField DataField="Name" HeaderText="姓名" />
<asp:BoundField DataField="PersonTypeName" HeaderText="人员类型名称" />
</Columns>
</asp:GridView>
后端:
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=DB;User ID=sa;password=1;");
SqlCommand cmd = new SqlCommand("select Person.Name,PersonType.Name as PersonTypeName from PersonType,Person
where PersonType.ID = Person.PersonTypeID", con);
SqlDataAdapter sda = new SqlDataAdapter();
DataSet ds = new DataSet();
sda.SelectCommand = cmd;
sda.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询