Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#3.0
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 23-Jan-13 20:35pm
Comments
Daniele Rota Nodari at 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 at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 6,696
1 Sergey Alexandrovich Kryukov 6,675
2 CPallini 5,315
3 George Jonsson 3,584
4 Gihan Liyanage 2,650


Advertise | Privacy | Mobile
Web02 | 2.8.140921.1 | Last Updated 30 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100