如何使用 ACCESS DB 连接来填充 gridview

发布于 2024-12-13 05:54:21 字数 594 浏览 2 评论 0原文

如何使用 Access 数据库的连接来填充 GridView

到目前为止我有以下代码:

OleDbConnection myConnection = default(OleDbConnection);
OleDbCommand myCommand = default(OleDbCommand);
string strSQL = null;
strSQL = "SELECT * FROM tblLoginInfo " + "WHERE username='" + CustID.Replace("'", "''") + "' " + "AND password='" + CustPass.Replace("'", "''") + "';";
myConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " + "Data Source=" + Server.MapPath("login.mdb") + ";");

myCommand = new OleDbCommand(strSQL, myConnection);
myConnection.Open();

但现在怎么办?

How can I populate a GridView using a connection to an Access Database?

So far I have the following code:

OleDbConnection myConnection = default(OleDbConnection);
OleDbCommand myCommand = default(OleDbCommand);
string strSQL = null;
strSQL = "SELECT * FROM tblLoginInfo " + "WHERE username='" + CustID.Replace("'", "''") + "' " + "AND password='" + CustPass.Replace("'", "''") + "';";
myConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " + "Data Source=" + Server.MapPath("login.mdb") + ";");

myCommand = new OleDbCommand(strSQL, myConnection);
myConnection.Open();

But now what ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

离不开的别离 2024-12-20 05:54:21
 OleDbConnection myConnection = default(OleDbConnection);
         OleDbCommand myCommand = default(OleDbCommand);
         string strSQL = null;
         strSQL = "SELECT * FROM tblLoginInfo " + "WHERE username='" + CustID.Replace("'", "''") + "' " + "AND password='" +
 CustPass.Replace("'", "''") + "';";
         myConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " + "Data Source="
 + Server.MapPath("login.mdb") + ";");
        myConnection.Open();
         myCommand = new OleDbCommand(strSQL, myConnection);

         OleDbDataAdapter adp=new OledbDataAdapter(myCommand);
         dataset ds=new dataset();
         adp.fill(ds);
        gridview.datasource=ds;
        gridview.databind();
 OleDbConnection myConnection = default(OleDbConnection);
         OleDbCommand myCommand = default(OleDbCommand);
         string strSQL = null;
         strSQL = "SELECT * FROM tblLoginInfo " + "WHERE username='" + CustID.Replace("'", "''") + "' " + "AND password='" +
 CustPass.Replace("'", "''") + "';";
         myConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " + "Data Source="
 + Server.MapPath("login.mdb") + ";");
        myConnection.Open();
         myCommand = new OleDbCommand(strSQL, myConnection);

         OleDbDataAdapter adp=new OledbDataAdapter(myCommand);
         dataset ds=new dataset();
         adp.fill(ds);
        gridview.datasource=ds;
        gridview.databind();
So尛奶瓶 2024-12-20 05:54:21

类似方法

        <asp:AccessDataSource ID="AccessDataSource1" runat="server" 
            DataFile="~/App_Data/AccesFile.mdb" SelectCommand="SELECT * FROM [TableName]">
        </asp:AccessDataSource>
        <asp:GridView ID="GridView1" runat="server" DataSourceID="AccessDataSource1">
        </asp:GridView>

尝试AccessDataSource、SqlDataSource 以及在 ASP.NET 中连接到 Access 数据库

我还发现了这篇关于 在 Asp.net 中将 GridView 与 MS Access 数据库表绑定

希望这有帮助

Try something like this

        <asp:AccessDataSource ID="AccessDataSource1" runat="server" 
            DataFile="~/App_Data/AccesFile.mdb" SelectCommand="SELECT * FROM [TableName]">
        </asp:AccessDataSource>
        <asp:GridView ID="GridView1" runat="server" DataSourceID="AccessDataSource1">
        </asp:GridView>

as mentioned in AccessDataSource, SqlDataSource and connecting to Access databases in ASP.NET

Also I found this article about Bind GridView with MS Access Database table in Asp.net

Hope this helps

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文