VBフォームアプリケーションで
PostgresのDBをコピーするプログラムを作成しています。
サーバAにあるPostgresのデータをサーバBのPostgresにコピーしたいです。
サーバAとサーバBは通信できず、クライアントのアプリケーションを中継してデータの同期を行う仕組みです。
クライアントからはサーバAもサーバBも通信可能です。
DBの定義はDataTableの列名とイコールになっています。
[サーバA] ⇔ [クライアント] ⇔ [サーバB]
サーバAからデータを取得し、DataTableにセットし、
サーバBへDataTableの情報で一括Insertできないかと考えています。
件数が10万~30万ほどになるのでDataTableをforで回すのは現実的でないと考えました。。。
DataTableに入れた後、データの編集は行いません。
SQLServer等ではDataTabeで一括Insertができる記事を見つけたのですが
Postgresでも可能なのでしょうか。
同じようなことをしてる方がいらっしゃったら教えていただきたいです
Npgsqlを使用しています
VB
1 'Postgres用データ取得 2 Private Function Get_DbData_postgres(Sql) 3Dim DataBase As String = "" 4 Dim User As String = "" 5 Dim Password As String = "" 6 Dim IpAddress As String = "" 7 Dim Port As String = "5432" 8 Dim PgCon As New NpgsqlConnection("Database=" + DataBase + ";port=" + Port + ";Server=" + IpAddress + ";User Id=" + User + ";Password=" + Password + ";") 9 10 11 Using PgCon 12 PgCon.Open() 13 Dim cmd As NpgsqlCommand = New NpgsqlCommand("SELECT * FROM TABLE_NAME", PgCon) 14 Dim da As NpgsqlDataAdapter = New NpgsqlDataAdapter(cmd) 15 Dim dt As DataTable = New DataTable() 16 da.Fill(dt) 17 18 PgCon.Close() 19 Return dt 20 End Using 21 End Function 22 'Postgres用データ更新 23 Private Function Insert_DbData_postgres(dt As DataTable, TableName As String) 24 Dim SQL As New System.Text.StringBuilder 25 Dim User As String = "" 26 Dim Password As String = "" 27 Dim IpAddress As String = "" 28 Dim Port As String = "5432" 29 Dim PgCon As New NpgsqlConnection("Database=" + DataBase + ";port=" + Port + ";Server=" + IpAddress + ";User Id=" + User + ";Password=" + Password + ";") 30 31 32 Using PgCon 33 SQL.AppendLine("INSERT INTO ") 34 SQL.AppendLine(TableName) 35 SQL.AppendLine(" VALUES(") 36 /* 37 * 38 *DataTableを使って一括Insertしたい。。。。。 39 * 40 */ 41 42 43 PgCon.Open() 44 Dim cmd As NpgsqlCommand = New NpgsqlCommand(SQL.ToString, PgCon) 45 cmd.ExecuteNonQuery() 46 PgCon.Close() 47 Return dt 48 End Using 49 End Function

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。