怎么把查询结果显示在GridView指定列
protectedvoidPage_Load(objectsender,EventArgse){stringstrSongName=Request.QueryString...
protected void Page_Load(object sender, EventArgs e)
{
string strSongName=Request.QueryString["name"];
if (!IsPostBack)
{
string strSql = "Select SongName,SongSinger,Album,DemandNum from Song where SongName='" + strSongName + "'";
string strConn = "Data Source=MICROSOF-3974A1;Initial Catalog=MusicWeb;User ID=sa;Password=yangxian";
SqlConnection myCon = new SqlConnection(strConn);
try
{
myCon.Open();
SqlCommand cmd = new SqlCommand(strSql, myCon);
gvSongSearchResult.DataSource = cmd.ExecuteReader();
gvSongSearchResult.DataBind();
}
catch (OleDbException ex)
{
Response.Write(ex);
}
finally
{
myCon.Close();
}
}
}
我想把查询结果这四项SongName,SongSinger,Album,DemandNum 分别显示在GridView四列里,怎么办?
gvSongSearchResult是GridView控件 展开
{
string strSongName=Request.QueryString["name"];
if (!IsPostBack)
{
string strSql = "Select SongName,SongSinger,Album,DemandNum from Song where SongName='" + strSongName + "'";
string strConn = "Data Source=MICROSOF-3974A1;Initial Catalog=MusicWeb;User ID=sa;Password=yangxian";
SqlConnection myCon = new SqlConnection(strConn);
try
{
myCon.Open();
SqlCommand cmd = new SqlCommand(strSql, myCon);
gvSongSearchResult.DataSource = cmd.ExecuteReader();
gvSongSearchResult.DataBind();
}
catch (OleDbException ex)
{
Response.Write(ex);
}
finally
{
myCon.Close();
}
}
}
我想把查询结果这四项SongName,SongSinger,Album,DemandNum 分别显示在GridView四列里,怎么办?
gvSongSearchResult是GridView控件 展开
2个回答
展开全部
分都没有、给个没分的友情提、把GridView每一列的数据源做绑定、绑定的名字就是你查询的列名。编辑列、有个数据源叫DataPropertyName把你查询的列名(以数据库表的列名为准)写在后面就可以了。唉、杯具啊、半夜帮你答题还没有分....现在养孩子也不容易啊....
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你要在前台的GirdView
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="SongName" HeaderText="歌曲名"/>
<asp:BoundField DataField="SongSinger" HeaderText="歌手"/>
<asp:BoundField DataField="Album" HeaderText="专辑名"/>
<asp:BoundField DataField="DemandNum" HeaderText="推荐度"/>
</Columns>
</asp:GridView>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="SongName" HeaderText="歌曲名"/>
<asp:BoundField DataField="SongSinger" HeaderText="歌手"/>
<asp:BoundField DataField="Album" HeaderText="专辑名"/>
<asp:BoundField DataField="DemandNum" HeaderText="推荐度"/>
</Columns>
</asp:GridView>
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询