0

This is my comma separated value file conversion code.

 string deliminator = ",";
 string tablename = "Converted";
        //string filelink = FileName.Text;
        string fileintro = FileName.Text;
        DataSet DS = new DataSet();
        StreamReader SR = new StreamReader(fileintro.Trim());
        DS.Tables.Add(tablename);

    DS.Tables[tablename].Columns.Add("A");
    DS.Tables[tablename].Columns.Add("B");
    DS.Tables[tablename].Columns.Add("C");
    DS.Tables[tablename].Columns.Add("D");
    DS.Tables[tablename].Columns.Add("E");
    DS.Tables[tablename].Columns.Add("F");
    DS.Tables[tablename].Columns.Add("G");
    DS.Tables[tablename].Columns.Add("H");
    DS.Tables[tablename].Columns.Add("I");

...

SQLiteConnectionconn=newSQLiteConnection(ConfigurationManager.ConnectionStrings["dbcon"].ConnectionString);           

SQLiteCommand cmd = new SQLiteCommand ("INSERT INTO ConvertData (a,b,c,d,e,f) values ('"+a+"'...), con);

                cmd.ExecuteNonQuery();
                co.Close();
                FileName.Text = "";
   }

it saves data in database table like "1,2,3,4,5,6,7" so how can i save it normally like 1,2,3,4,5,6,into database columns.'

Reaz Murshed
  • 23,691
  • 13
  • 78
  • 98
Snack'Eyes
  • 125
  • 7
  • You should show code that 1) can be compiled and 2) contains all necessary data. What are the datatypes of your columns? What is `a`? in your query? Show the complete query and all variables you are putting into it and how you construct them – derpirscher Apr 30 '16 at 05:04

1 Answers1

0

The data from comma separate files are exported as string. So before inserting into the database tables convert them into required data types. For examples, if the data type in the table is int, use the Parse function and convert the string to integer before inserting, You need to repeat this for all columns

int Id = Int32.Parse(ExcelCol1.Text);

If you are looking for a detailed approach, the below link will help you

Uploading an Excel sheet and importing the data into SQL Server database

Community
  • 1
  • 1
Sankar Krishnamoorthy
  • 1,255
  • 13
  • 18
  • NO ACTUALLY PROBLEM IS conversion done completely but in database table first column nd last column save data like "A......Z" – Snack'Eyes Apr 30 '16 at 05:13