C# PostgreSQL复制入和NPGSQL
我正在尝试将数据从stream复制到postgresC# PostgreSQL复制入和NPGSQL,c#,postgresql,bulkinsert,npgsql,C#,Postgresql,Bulkinsert,Npgsql,我正在尝试将数据从stream复制到postgres 我已经准备好文件fl.ext: 1TaboneReturn 2tabtworreturn 3TabthreeReturn 4AbslonyReturn 并编写了测试代码: StreamReader sr = new StreamReader(Console.ReadLine()); NpgsqlCommand cmd = new NpgsqlCommand(string.Format("COPY {0}(id, text) FROM STDI
我已经准备好文件fl.ext:
1TaboneReturn
2tabtworreturn
3TabthreeReturn
4AbslonyReturn
并编写了测试代码:
StreamReader sr = new StreamReader(Console.ReadLine());
NpgsqlCommand cmd = new NpgsqlCommand(string.Format("COPY {0}(id, text) FROM STDIN;", tableName), connection);
NpgsqlCopyIn cin = new NpgsqlCopyIn(cmd, connection, sr.BaseStream);
connection.Open();
cin.Start();
cin.End();
cin.Close();
但是它在cin.Start()
上失败,{“对象引用未设置为对象的实例。”}
并且没有其他详细信息我做错了什么,伙计们?只需在
connection.Open()之后移动NpgsqlCommand
和NpgsqlCopyIn
声明即可解决问题代码>。现在可以了