Click here to Skip to main content
15,886,795 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have written this function to write the data in database after reading the data from a file.
It stops working after " copyIn.Start ". I don't know whats the problem.
Any help will be great.

C#
private void SaveAllByCopy(DateTime datetaken, string Weight, string lineno)
        {
           using (var connection = new NpgsqlConnection("Server=localhost ; port=5432; Database=testdb;Userid=postgres; Password=admin "))
                {
                    connection.Open();
                    using (var command = connection.CreateCommand())
                    { 
  command.CommandText = "COPY finaltest(datetaken,Weight,lineip) FROM STDIN";
  NpgsqlCopySerializer serializer = new NpgsqlCopySerializer(connection);
  NpgsqlCopyIn copyIn = new NpgsqlCopyIn(command, connection, serializer.ToStream);
                        try
                        {
                            copyIn.Start();
                                    foreach (var value in conairdata)
                                     {
                                        serializer.AddString(conairdata.datetaken);
                                         serializer.AddString(conairdata.Weight);
                                         serializer.AddDateTime(conairdata.lineno);
                                         serializer.EndRow();
                                         serializer.Flush();
                                     }
					 copyIn.End();
                                      serializer.Close();
                       }
Posted
Comments
PIEBALDconsult 29-Jul-14 1:17am    
"stops working" doesn't tell us much.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900