保存的文件不可读 [英] saved file is not readable

查看:135
本文介绍了保存的文件不可读的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在从访问系统导出表并导入表。这个表已经保存但是它不可读,也没有导入。我按照下面的代码,

if(radioButton7.Checked == true)

{

da = new OleDbCommand(从xxx中删除,con);

da.ExecuteNonQuery();

foreach(dt.Rows中的DataRow dr)

{

OleDbCommand da1 = new OleDbCommand (插入xxx值(+ dr [0] .ToString()+,''+ dr [1] .ToString()+'',''+ dr [2] .ToString()+ '', '' + DR [3]的ToString()+ '', + DR [4]的ToString()+ + DR [5]的ToString()+, '' + DR [6]的ToString()+ '', '' + DR [7]的ToString()+ '', + DR [8]的ToString()+ '' + DR [ 9]的ToString()+ '', '' + DR [10]的ToString()+ '', + DR [11]的ToString()+ '' + DR [12]。的ToString()+ '', '' + DR [13]的ToString()+ '', '' + DR [14]的ToString()+ '', '' + DR [15]的ToString()+ '', + DR [16]的ToString()+ '' + DR [17]。为了String()+''),con);

da1.ExecuteNonQuery();

}

Hi,
I''m exporting table from access to system and importing the table.The table is getting saved but its not readable and not getting imported also.I have follow the below code,
if (radioButton7.Checked == true)
{
da = new OleDbCommand(Delete from xxx", con);
da.ExecuteNonQuery();
foreach (DataRow dr in dt.Rows)
{
OleDbCommand da1 = new OleDbCommand("insert into xxx values("+dr[0].ToString()+",''"+dr[1].ToString()+"'',''"+dr[2].ToString()+"'',''"+dr[3].ToString()+"'',"+dr[4].ToString()+","+dr[5].ToString()+",''"+dr[6].ToString()+"'',''"+dr[7].ToString()+"'',"+dr[8].ToString()+",''"+dr[9].ToString()+"'',''"+dr[10].ToString()+"'',"+dr[11].ToString()+",''"+dr[12].ToString()+"'',''"+dr[13].ToString()+"'',''"+dr[14].ToString()+"'',''"+dr[15].ToString()+"'',"+dr[16].ToString()+",''"+dr[17].ToString()+"'')", con);
da1.ExecuteNonQuery();
}

推荐答案

你应该尝试一些事情:

1)不要连接字符串来构建SQL命令。它让您对意外或故意的SQL注入攻击持开放态度,这可能会破坏您的整个数据库。请改用参数化查询。这可能有助于解决您的问题,具体取决于您的数据内容。

2)在完成OleDbCommands之后尝试处置它们 - 它们是有限的资源,不应该留给垃圾收集器摆脱它们。

3)查看你的输出文件,并确保它的格式不会超过你试图从中读取的任何格式。尝试在代码中打开它,选择几个项目,然后再次关闭它。该文件仍然可读吗?



如果这些都没有帮助,我们需要更多地了解您实际连接的内容 - OleDb可以连接到一个巨大的各种来源,你不告诉我们哪一个。
There are a couple of things that you should try:
1) Do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead. This may help with your problem, depending on your data content.
2) Try Disposing of your OleDbCommands when you have finished with them - they are a limited resource, and should not be left to the Garbage collector to get rid of them.
3) Look at your output file, and make sure that it isn''t in a later format than whatever you are trying to read it from. Try opening it in your code, selecting a few items, and closing it again. Is the file "still readable"?

If none of this helps, we would need to know more about what you are actually connecting to - OleDb can connect to a huge variety of sources, and you don''t tell us which.


对于导出和导入Excel文件,我们需要按照以下步骤

1.我们需要从工具箱中添加saveFileDialog1和openFileDialog1。

2.在saveFileDialog1->右键单击 - >属性。

3.In属性过滤器选项将可用。 />
4 ..在过滤选项中我们需要写下面的行,

(* .xls)| * .xls

5.如果我们正在导出将以Excel方法保存的文件。
For Exporting and Importing Excel File we need to follow the below steps
1.We need to add saveFileDialog1 and openFileDialog1 from toolbox.
2.In saveFileDialog1->Right Click->Properties.
3.In Properties Filter option will be available.
4..In Filter Option we need to write the below line,
(*.xls)|*.xls
5.Now if we are exporting the file it will be saved in Excel method.


这篇关于保存的文件不可读的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆