日期:2014-05-18  浏览次数:20899 次

读取数据库数据后 怎么写入到RichTextBox中?
RT 求助

------解决方案--------------------
C# code

  private void Form1_Load(object sender, EventArgs e)
        {
            string connStr, selectCmd;
            int i;
            connStr =
            "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=SCOREDB.mdb";
            selectCmd = "SELECT * FROM SCORE";
            OleDbConnection conn;
            OleDbCommand cmd;
            OleDbDataReader reader;
            conn = new OleDbConnection(connStr);
            conn.Open();
            cmd = new OleDbCommand(selectCmd, conn);
            reader = cmd.ExecuteReader();

            for (i = 0; i < reader.FieldCount; i++)
            {
                txtShow.Text += reader.GetName(i) + "\t";
            }
            txtShow.Text += "\n\n";

            while (reader.Read())
            {
                for (i = 0; i < reader.FieldCount; i++)
                {
                    txtShow.Text += reader[i] + "\t";
                }
                txtShow.Text += "\n";
            }
            conn.Close();
        }