none
csv file in sql table

All replies

  • can i import csv file from ftp server  and insert it into mulptiple sql tables using c#.
    Thursday, October 31, 2013 2:03 AM
  • If possible you can use SSIS(It has ftp task and data flow task to load from csv file), it would be easier to do. yes you can also do with C# but you need to code.

    Here is sample to download file from FTP: http://msdn.microsoft.com/en-us/library/ms229711.aspx

    To load CSV in table : http://www.codeproject.com/Articles/290242/Import-Data-from-a-Text-or-CSV-file-into-SQL-Serve


    Regards Harsh

    Thursday, October 31, 2013 2:18 AM
  • Hi,

    Try this link .


    sathya - www.allaboutmssql.com ** Mark as answered if my post solved your problem and Vote as helpful if my post was useful **.

    Thursday, October 31, 2013 2:29 AM
  • Thanks for response.

    Im not using SSIS.

    By using c# trying to insert one csv file from ftp server in  3 sql server tables .By spliting csv 3 cols in one table,3 cols in another table.

    FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://uri:port/Wired/buildin.csv");

                request.Method =

    WebRequestMethods.Ftp.ListDirectoryDetails;

               

    // This example assumes the FTP site uses anonymous logon.


                request.Credentials =

    new NetworkCredential("WIREDNYC@argent.local", "Password1");

               

    try


                {

                   

    FtpWebResponse response = (FtpWebResponse)request.GetResponse();

                   

    Stream responseStream = response.GetResponseStream();

                   

    StreamReader reader = new StreamReader(responseStream);

                   

    string line = reader.ReadLine();

                   

    StringBuilder result = new StringBuilder();

                   

    while (line != null)

                    {

                        result.Append(line);

                        result.Append(

    "\n");

                        line = reader.ReadLine();

                    }

                   

    List<FTPFileSystem> subDirs = new List<FTPFileSystem>();

                   

    string subDir = reader.ReadLine();

                   

    // Find out the FTP Directory Listing Style from the recordString.


                    FTPDirectoryListingStyle style = FTPDirectoryListingStyle.MSDOS;

                   

    if (!string.IsNullOrEmpty(subDir))

                    {

                        style = FTPFileSystem.GetDirectoryListingStyle(subDir);

                    }

                   

    while (!string.IsNullOrEmpty(subDir))

                    {

                        subDirs.Add(FTPFileSystem.ParseRecordString(url, subDir, style));

                        subDir = reader.ReadLine();

                    }

                   

    return subDirs;

                }

               

    finally


                {

                   

    if (response != null)

                    {

                        response.Close();

                    }

                   

    // Close the StreamReader object and the underlying stream, and release


                   

    // any system resources associated with the reader.


                   

    if (reader != null)

                    {

                        reader.Close();

                    }

                }

                }

    public static void LoadCsvDataIntoSqlServer(string bbbl,string name,string building,string phone)


           

    {



       


           

       SqlCommand cmd=new SqlCommand ();


           

       cmd.CommandText ="insert into builderstable values(@bbbl,@name,@building_name,@phone)" ;

    cmd.Parameters.AddWithValue(@bbbl,bbbl);

    cmd.Parameters .AddWithValue (@name,name);


           

    / cmd.Parameters.AddWithValue (@building,building);


           

      cmd.Parameters .AddWithValue (@phone,phone);

    con.Open ();cmd.ExecuteNonQuery ();



          


              

    SqlConnection con=new SqlConnection (connectionString );
    string connectionString = "Data Source=joyce;database=Test  ;User ID= sa ;Password= Sqluser123";
    Thursday, October 31, 2013 5:48 PM