我使用的是VS.NET 2003,和SQL Server 2000数据库,请问怎么将pubs数据库中的authors表中的数据显示出来?
我用的是sqlConnection,sqlAdapter,和DataSet,DataGrid控件,但试了好几次都不成功,请教各位具体的步骤怎么做。
我用的是sqlConnection,sqlAdapter,和DataSet,DataGrid控件,但试了好几次都不成功,请教各位具体的步骤怎么做。
解决方案 »
- asp.net上传控件的问题..
- asp.net网站运行时如何只打开一个页面
- 帮忙看下租车表怎么实现的?
- 如何得到DetailList中模版列中控件的值?
- 同样的内容,扩展名不一样,结果也不一样(关于网页编码的问题,内详)
- 源代码管理: 项目中某些文件或文件夹的名称与当前系统 ANSI 代码页不兼容。
- ASP.NET如何挂接一个执行程序
- 高手送高手。实现DataGrid透明怎么做? (100分)
- ASP.NET中使用ToolBar控件,但該控件無法設置成客戶端運行,
- 装过vs.net2003英文版的进来看看吧,谢谢了。
- 强类型DataSet问题
- 有关ASP.net在三层体系结构运行配置的问题?
SqlConnection MyConn = new SqlConnection(StrSql);
MyConn.Open();
string CommSql = "select * from authors";
SqlDataAdapter adp = new SqlDataAdapter(CommSql,MyConn);
DataSet ds = new DataSet();
adp.Fill(ds);
DataGrid1.DataSource = ds;
DataGrid1.DataBind();
MyConn.Close();
con.open();
string strsql="select * from pubs"';
sqldataadapert sda=new ...(strsql,con);
dataset ds=new ..
sda.fill(ds,"sdfs")
datagrid1.datasource=ds.table[0].defaultview
datagrid1.databind();手写的可能有些地方不对,大体上差不多
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Data.SqlClient.SqlException: 用户 'sa' 登录失败。原因: 未与信任 SQL Server 连接相关联。还有上面的那段代码应该放在什么地方?
SqlConnection MyConn = new SqlConnection(StrSql);
MyConn.Open();
string CommSql = "select * from authors";
System.Data.SqlClient.SqlCommand cmd=new System.Data.SqlClient.SqlCommand(CommSql,MyConn);
System.Data.SqlClient.SqlDataReader myreader=cmd.ExecuteReader();
DataGrid1.DataSource = myreader;
DataGrid1.DataBind();
MyConn.Close();using DataSet:String StrSql="server=yourIP;uid=yourid;password=yourpassword;database=pubs";
SqlConnection MyConn = new SqlConnection(StrSql);
MyConn.Open();
string CommSql = "select * from authors";
SqlDataAdapter adp = new SqlDataAdapter(CommSql,MyConn);
DataSet ds = new DataSet();
adp.Fill(ds);
DataGrid1.DataSource = ds;
DataGrid1.DataBind();
MyConn.Close();
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<script runat="server"> void Page_Load(object sender, EventArgs e) {
if (!Page.IsPostBack) {
// Databind the data grid on the first request only
// (on postback, rebind only in paging command)
BindGrid();
}
}
void DataGrid_Page(object sender, DataGridPageChangedEventArgs e) {
DataGrid1.CurrentPageIndex = e.NewPageIndex;
BindGrid();
}
void BindGrid() {
// TODO: update the ConnectionString and CommandText values for your application
string ConnectionString = "server=(local);database=pubs;trusted_connection=true";
string CommandText = "select au_lname, au_fname, address, city, state from Authors order by au_lname";
SqlConnection myConnection = new SqlConnection(ConnectionString);
SqlDataAdapter myCommand = new SqlDataAdapter(CommandText, myConnection);
DataSet ds = new DataSet();
myCommand.Fill(ds);
DataGrid1.DataSource = ds;
DataGrid1.DataBind();
}</script>
<html>
<head>
</head>
<body style="FONT-FAMILY: arial">
<h2>Data Report with Paging
</h2>
<hr size="1" />
<form runat="server">
<asp:datagrid id="DataGrid1" runat="server" width="80%" CellSpacing="1" GridLines="None" CellPadding="3" BackColor="White" ForeColor="Black" OnPageIndexChanged="DataGrid_Page" PageSize="6" AllowPaging="true">
<HeaderStyle font-bold="True" forecolor="white" backcolor="#4A3C8C"></HeaderStyle>
<PagerStyle horizontalalign="Right" backcolor="#C6C3C6" mode="NumericPages"></PagerStyle>
<ItemStyle backcolor="#DEDFDE"></ItemStyle>
</asp:datagrid>
</form>
</body>
</html>
碰到过,最有可能的原因是,忘记调用DataAdapter 的 Fill 方法了