Click here to Skip to main content
15,886,788 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
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();
}
Posted
Comments
Daniele Rota Nodari 24-Jan-13 2:55am    
Hi.
You wrote that the exported file is not readable, but the sample code you provided shows only import function.
You should add more details about export process or about importing errors or imported results.
Balamurugan1989 24-Jan-13 3:05am    
Ya i'm exporting and importing 3 tables first 2 tables process working fine it has been exported and imported successfully.3rd table is getting saved in system but it cant able to edit the file showing as readable.

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.
 
Share this answer
 
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900