怎样在asp.net中用access数据库实现Gridview数据绑定
stringconnection="Provider=Microsoft.Jet.OLEDB.4.0;DataSource="+HttpContext.Current.S...
string connection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + HttpContext.Current.Server.MapPath(@"News.mdb");
OleDbConnection oledb = new OleDbConnection(connection);
oledb.Open();
OleDbCommand orderscmd = new OleDbCommand("select * from Newss",connection);
OleDbDataAdapter da = new OleDbDataAdapter(orderscmd, oledb);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
提示应用程序中的服务器错误
用formview绑定
int id = Convert.ToUInt16(Session["ID"]);
string connection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + HttpContext.Current.Server.MapPath(@"News.mdb");
OleDbConnection oledb = new OleDbConnection(connection);
oledb.Open();
OleDbCommand orderscmd = new OleDbCommand("select * from Newss where ID='"+id+"'");
OleDbDataAdapter da = new OleDbDataAdapter(orderscmd, oledb);
DataSet ds = new DataSet();
da.Fill(ds);
FormView1.DataSource = ds;
FormView1.DataBind();
提示:错误 7 参数“1”: 无法从“System.Data.OleDb.OleDbCommand”转换为“string” f:\wwwroot\Default.aspx.cs 30 52 f:\wwwroot\
请给位大侠帮帮忙,我需要详细代码,我考试用。详细代码 展开
OleDbConnection oledb = new OleDbConnection(connection);
oledb.Open();
OleDbCommand orderscmd = new OleDbCommand("select * from Newss",connection);
OleDbDataAdapter da = new OleDbDataAdapter(orderscmd, oledb);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
提示应用程序中的服务器错误
用formview绑定
int id = Convert.ToUInt16(Session["ID"]);
string connection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + HttpContext.Current.Server.MapPath(@"News.mdb");
OleDbConnection oledb = new OleDbConnection(connection);
oledb.Open();
OleDbCommand orderscmd = new OleDbCommand("select * from Newss where ID='"+id+"'");
OleDbDataAdapter da = new OleDbDataAdapter(orderscmd, oledb);
DataSet ds = new DataSet();
da.Fill(ds);
FormView1.DataSource = ds;
FormView1.DataBind();
提示:错误 7 参数“1”: 无法从“System.Data.OleDb.OleDbCommand”转换为“string” f:\wwwroot\Default.aspx.cs 30 52 f:\wwwroot\
请给位大侠帮帮忙,我需要详细代码,我考试用。详细代码 展开
1个回答
展开全部
//前台代码
<asp:GridView ID="GridSelect" runat="server" AllowPaging="True" AutoGenerateColumns="False" Width="662px" Font-Size="9pt" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Horizontal" AllowSorting="True" OnPageIndexChanging="GridSelect_PageIndexChanging" OnRowDataBound="GridSelect_RowDataBound" EmptyDataText="没有找到相关数据,请确定你查找的数据是否存在!">
<Columns>
<asp:BoundField DataField="StuXueHao" HeaderText="学生证号" />
<asp:BoundField DataField="StuKeCheng" HeaderText="考试课程" />
<asp:BoundField DataField="StuDan" HeaderText="单选成绩" />
<asp:BoundField DataField="StuDuo" HeaderText="多选成绩" />
<asp:BoundField DataField="StuZong" HeaderText="总成绩" />
</Columns>
<FooterStyle BackColor="#CCCC99" ForeColor="Black" />
<SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
<HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
</asp:GridView>
//后台代码
public void BangDing()
{
pengbll bll = new pengbll();
string Cheng = txtSelect.Text;
GridSelect.DataSource = bll.ChengSelect(Cheng);
GridSelect.DataKeyNames = new string[] { "StuXueHao" };
GridSelect.DataBind();
}
<asp:GridView ID="GridSelect" runat="server" AllowPaging="True" AutoGenerateColumns="False" Width="662px" Font-Size="9pt" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Horizontal" AllowSorting="True" OnPageIndexChanging="GridSelect_PageIndexChanging" OnRowDataBound="GridSelect_RowDataBound" EmptyDataText="没有找到相关数据,请确定你查找的数据是否存在!">
<Columns>
<asp:BoundField DataField="StuXueHao" HeaderText="学生证号" />
<asp:BoundField DataField="StuKeCheng" HeaderText="考试课程" />
<asp:BoundField DataField="StuDan" HeaderText="单选成绩" />
<asp:BoundField DataField="StuDuo" HeaderText="多选成绩" />
<asp:BoundField DataField="StuZong" HeaderText="总成绩" />
</Columns>
<FooterStyle BackColor="#CCCC99" ForeColor="Black" />
<SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
<HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
</asp:GridView>
//后台代码
public void BangDing()
{
pengbll bll = new pengbll();
string Cheng = txtSelect.Text;
GridSelect.DataSource = bll.ChengSelect(Cheng);
GridSelect.DataKeyNames = new string[] { "StuXueHao" };
GridSelect.DataBind();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询