同样大小的txt文件,一个是在别人的机子上从doc转换格式过来的,一个是在我自己机器上用txt写出来的,我机器上出来的txt文件就可以载入,doc转换过来的就不行,这是为什么?
access的备注字段可以最多为65535字符,相当于65535字节,也就是65k,为什么有些txt才15k左右就不能写入??求助各位!!
代码如下:
string dir="C:\\Documents and Settings\\Administrator\\桌面\\新建文件夹"public void FindFile(string dir)
{
DirectoryInfo Dir = new DirectoryInfo(dir); OleDbConnection Myconn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" + MdbPath + "';Jet OleDb:DataBase Password=123");
Myconn.Open();
try
{
foreach (DirectoryInfo d in Dir.GetDirectories())
{
FindFile(Dir + "\\" + d.ToString() + "\\");
}
foreach (FileInfo f in Dir.GetFiles("*.*"))
{
//把txt文件名,内容写入数据库
if (f.Extension == ".txt")
{
//读取txt内容
StreamReader TxtReader = new StreamReader(f.DirectoryName + "\\" + f.Name, System.Text.Encoding.GetEncoding("gb2312"));
//写入数据库
OleDbCommand Txt = new OleDbCommand("INSERT INTO 文本文件(已阅,文件名,正文) VALUES ('','" + f.Name + "','" + TxtReader.ReadToEnd().ToString() + "')", Myconn);
Txt.ExecuteNonQuery(); }
if (f.Extension == ".TXT")
{
//读取txt内容
StreamReader TxtReader = new StreamReader(f.DirectoryName + "\\" + f.Name, System.Text.Encoding.GetEncoding("gb2312"));
//写入数据库
OleDbCommand Txt = new OleDbCommand("INSERT INTO 文本文件(已阅,文件名,正文) VALUES ('','" + f.Name + "','" + TxtReader.ReadToEnd().ToString() + "')", Myconn);
Txt.ExecuteNonQuery(); } }
}
catch (Exception )
{ }
Myconn.Close();
}
access的备注字段可以最多为65535字符,相当于65535字节,也就是65k,为什么有些txt才15k左右就不能写入??求助各位!!
代码如下:
string dir="C:\\Documents and Settings\\Administrator\\桌面\\新建文件夹"public void FindFile(string dir)
{
DirectoryInfo Dir = new DirectoryInfo(dir); OleDbConnection Myconn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" + MdbPath + "';Jet OleDb:DataBase Password=123");
Myconn.Open();
try
{
foreach (DirectoryInfo d in Dir.GetDirectories())
{
FindFile(Dir + "\\" + d.ToString() + "\\");
}
foreach (FileInfo f in Dir.GetFiles("*.*"))
{
//把txt文件名,内容写入数据库
if (f.Extension == ".txt")
{
//读取txt内容
StreamReader TxtReader = new StreamReader(f.DirectoryName + "\\" + f.Name, System.Text.Encoding.GetEncoding("gb2312"));
//写入数据库
OleDbCommand Txt = new OleDbCommand("INSERT INTO 文本文件(已阅,文件名,正文) VALUES ('','" + f.Name + "','" + TxtReader.ReadToEnd().ToString() + "')", Myconn);
Txt.ExecuteNonQuery(); }
if (f.Extension == ".TXT")
{
//读取txt内容
StreamReader TxtReader = new StreamReader(f.DirectoryName + "\\" + f.Name, System.Text.Encoding.GetEncoding("gb2312"));
//写入数据库
OleDbCommand Txt = new OleDbCommand("INSERT INTO 文本文件(已阅,文件名,正文) VALUES ('','" + f.Name + "','" + TxtReader.ReadToEnd().ToString() + "')", Myconn);
Txt.ExecuteNonQuery(); } }
}
catch (Exception )
{ }
Myconn.Close();
}
那么不可见字符怎么处理掉呢?
我用System.IO.StreamReader.ReadLine()试了,也写不进access,但是用messagebox.show()能显示出文本的内容,请问怎么解决
new OledbParameter("@id",OledbType.int)
};
param[0].value=5;
cmd.parameters.add(param[0]);
cmd.executeNonQuery();
类似于这样的。