ACCESS的Ole对象读取
Ole对象在Access中存储为二进制文件,读取的时候需要注意转换出的文件的编码格式
1OleDbConnection OleConn = new OleDbConnection();
2OleConn.ConnectionString =
@"Provider=Microsoft.Jet.OleDb.4.0;data source=D:\WorkStation\Dialy_Sol\Dialy\Dialy.mdb";
3OleDbCommand OleCmd = new OleDbCommand();
4OleCmd.Connection = OleConn;
5OleCmd.CommandType = CommandType.Text;
6OleCmd.CommandText =
"SELECT Dialy_Content FROM Dialy_Info WHERE Dialy_Date='2008-5-2'";
7if (OleConn.State == ConnectionState.Closed)
8{
9OleConn.Open();
10}
11string DialyContent = "";
12byte[] Buff = new byte[1000];
13OleDbDataReader OleReader = OleCmd.ExecuteReader();
14while (OleReader.Read())
15{
16OleReader.GetBytes(0, 0, Buff, 0, 1000);
17DialyContent += Encoding.Unicode.GetString(Buff);
18}
< /span>19< span style="color: #000000;"> //DialyContent就是 读取出来后的中文
2OleConn.ConnectionString =
@"Provider=Microsoft.Jet.OleDb.4.0;data source=D:\WorkStation\Dialy_Sol\Dialy\Dialy.mdb";
3OleDbCommand OleCmd = new OleDbCommand();
4OleCmd.Connection = OleConn;
5OleCmd.CommandType = CommandType.Text;
6OleCmd.CommandText =
"SELECT Dialy_Content FROM Dialy_Info WHERE Dialy_Date='2008-5-2'";
7if (OleConn.State == ConnectionState.Closed)
8{
9OleConn.Open();
10}
11string DialyContent = "";
12byte[] Buff = new byte[1000];
13OleDbDataReader OleReader = OleCmd.ExecuteReader();
14while (OleReader.Read())
15{
16OleReader.GetBytes(0, 0, Buff, 0, 1000);
17DialyContent += Encoding.Unicode.GetString(Buff);
18}
< /span>19< span style="color: #000000;"> //DialyContent就是 读取出来后的中文