0

我试图在 C# 中连接 MS Access Db 并想查看全部。我的 Db 连接代码如下所示

String conStr= @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Administrator\Desktop\SMSGateway2\SMS.mdb;Persist Security Info=True; Jet OLEDB:Database Password=testing" ;

        OleDbConnection con;
        con = new OleDbConnection(conStr);
        string cmdString = "select * from Temp_Order";
        OleDbCommand command = new OleDbCommand(cmdString, con);

        try
        {
            con.Open();
            command.ExecuteNonQuery();

            OleDbDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                richTextBox1.Text = "Student Name: " + reader["SenderNo"].ToString() + "\n" +
                   "ID: " + reader["OrgerView"].ToString() + "\n" +
                   "Program: " + reader["OrderTime"].ToString() + "\n" +
                   "Address: " + reader["Flag"].ToString();
            }


        }
        catch (Exception readexcp)
        {
            throw readexcp;
        }
        finally
        {
            con.Close();
        }
4

1 回答 1

0

首先删除此行 command.ExecuteNonQuery();,然后检查 SenderNo、OrgerView、OrderTime 和 Flag 是有效的列名。

于 2012-04-06T07:56:50.773 回答