Hello Aman,
Here is the Code to Import and store the csv file into Database:
Here is the Function to import the CSV Data:
public DataSet ConnectCSV (string filetable)
{
DataSet ds = new DataSet ();
try
{
string strConnString=
"Driver={Microsoft Text Driver (*.txt;*.csv)};
Dbq="+txtCSVFolderPath.Text.Trim()+";
Extensions=asc,csv,tab,txt;
Persist Security Info=False";
string sql_select;
System.Data.Odbc.OdbcConnection conn;
//Create connection to CSV file
conn = new System.Data.Odbc.OdbcConnection(
strConnString.Trim ());
//Open the connection
conn.Open ();
//Fetch records from CSV
sql_select="select * from ["+ filetable +"]";
obj_oledb_da=new System.Data.Odbc.OdbcDataAdapter(
sql_select,conn);
obj_oledb_da.Fill(ds,"Stocks");
//Set the datagrid properties
dGridCSVdata.DataSource=ds;
dGridCSVdata.DataMember="Stocks";
//Close Connection to CSV file
conn.Close ();
}
catch (Exception e)
{
MessageBox.Show (e.Message);
}
return ds;
Below the Code to Insert the CSV Data: