![]() ![]() Create a SQL table based on the first row count (which is the header for the file). ![]() How can I combine the code posted in the beginning with the above code to do the following: MessageBox.Show(colArray.Count + "") //displays the count for the columns for each lineĬolArray.Clear() //clear the column to use it for next line While (!parser.EndOfData) //while file is being readįoreach (string field in fields) //for each column Parser.TextFieldType = FieldType.Delimited Using (TextFieldParser parser = new TextFieldParser(textBox1.Text)) I have the following code which reads each line in the CSV file and gets the fields for each line and adds it to a List array: var lines = File.ReadLines(textBox1.Text) įoreach (string line in lines) //for each line ![]() I have a CSV that I am also trying to do the same for but not sure how to do it. The above code is an example for the Excel file. The textboxes are as follows: //tbXLSBrowse.Text = the excel file name SqlCommand addcolumn = new SqlCommand("ALTER TABLE " + tb.Text + " ADD varchar(MAX)", m圜onnection) SqlCommand createtable = new SqlCommand("CREATE TABLE " + tb.Text + " (" + dc.ColumnName + " varchar(MAX))", m圜onnection) selecting each column of the datatable to create a table in the database SqlCommand cmd = new SqlCommand("SELECT * FROM sysobjects where name = '" + tb.Text + "'", m圜onnection) checking whether the table selected from the dataset exists in the database or not M圜onnection = new SqlConnection(cString) OleDbCommand command = new OleDbCommand("Select * FROM ", oConn) //change to the sheet nameĭataTableReader reader = dt.CreateDataReader() I have existing code which creates a new table based on the columns of a file (DBF, Excel): OleDbConnection oConn = new Source='" + tbXLSBrowse.Text + "' Extended Properties=\"Excel 12.0 xml HDR=Yes IMEX=1\"") ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |