[pgsql-jp: 34883] Re: Visual Studio .NET から使いたい

TANABE JUnnichi jun @ lmns.biz
2005年 2月 13日 (日) 05:59:22 JST


田邉と申します。投稿してちょっと気になったので少しやってみました。

    Dim cnn As Npgsql.NpgsqlConnection = New Npgsql.NpgsqlConnection()
    Dim dsTest As DataSet = New DataSet("dsTest")
    Dim adp As Npgsql.NpgsqlDataAdapter = New Npgsql.NpgsqlDataAdapter()

と宣言しといて・・・・、

        Npgsql.NpgsqlEventLog.Level = Npgsql.LogLevel.Debug
        Npgsql.NpgsqlEventLog.Level = Npgsql.LogLevel.Normal
        Npgsql.NpgsqlEventLog.LogName = "pg_trace.log"
        Npgsql.NpgsqlEventLog.EchoMessages = True

        cnn.ConnectionString =
"SERVER=localhost;DATABASE=test;TIMEOUT=0;USER
ID=hoge;PASSWORD=fuga;Encoding=UNICODE;"
        Try
            cnn.Open()
            dsTest.Clear()
            adp.SelectCommand = New Npgsql.NpgsqlCommand("select * from foo
order by id", cnn)
            adp.Fill(dsTest, "foo")
            Dim cb As Npgsql.NpgsqlCommandBuilder = New
Npgsql.NpgsqlCommandBuilder(adp)
            adp.InsertCommand =
cb.GetInsertCommand(dsTest.Tables("foo").Rows(0))
            adp.UpdateCommand =
cb.GetUpdateCommand(dsTest.Tables("foo").Rows(0))
            adp.DeleteCommand =
cb.GetDeleteCommand(dsTest.Tables("foo").Rows(0))

            DataGrid1.DataSource = dsTest.Tables("foo")
        Catch ex As Exception
            MsgBox(ex.Message.ToString, MsgBoxStyle.Information, "エラー")
        Catch ex As DBConcurrencyException
            MsgBox(ex.Message.ToString, MsgBoxStyle.Information, "同時更新エ
ラー")
        Catch ex As Npgsql.NpgsqlException
            MsgBox(ex.Message.ToString, MsgBoxStyle.Information, "Pgsqlエ
ラー")
        End Try


みたいにすると、1行でもレコードがある時は
        adp.Update(dsTest, "foo")
を発行することで正常に更新できるみたいです。

・・・・が、データが1件も無いと・・・・、
「位置0に行がありません」
となります。(当然か)
            adp.InsertCommand =
cb.GetInsertCommand(dsTest.Tables("foo").Rows(0))
            adp.UpdateCommand =
cb.GetUpdateCommand(dsTest.Tables("foo").Rows(0))
            adp.DeleteCommand =
cb.GetDeleteCommand(dsTest.Tables("foo").Rows(0))
を書かずに済むようになるのが一番望ましいですが、これが必須にしてもせめて
            adp.InsertCommand = cb.GetInsertCommand()
            adp.UpdateCommand = cb.GetUpdateCommand()
            adp.DeleteCommand = cb.GetDeleteCommand()
と書かせて欲しいところです。
# 無理やり最初に1行insertしておくしかない?(苦笑

以上、よろしくお願いいたします。

----- Original Message ----- 
From: "TANABE JUnnichi" <jun @ lmns.biz>
To: <pgsql-jp @ ml.postgresql.jp>
Sent: Sunday, February 13, 2005 5:16 AM
Subject: [pgsql-jp: 34882] Re: Visual Studio .NET から使いたい


> >
> ちょっと横道にそれますが、NpgsqlでCommandBuilderって、
> 皆様どうされてるんでしょうか。
>
> 最近Npgsqlの特集記事を良く見かけるようになり、その都度
> ものすごく期待して目を通すのですが、クエリを直接発行する
> タイプのものがほとんどでいつも悲しい思いをしていたりします。
> # 失礼な書き方かもしれませんが、別に文句を言いたい訳
> # ではないです。
> PgSqlClientですと、それもどきのことは出来るのですが、更新が
> 異様に遅いのと、一々手動でGetInsertCommand,
> GetUpdateCommand, GetDeleteCommandを別々にDataAdapter
> に返してやる必要があり、これもまた異様に速度が遅いので、
> 最近まで利用してたんですが、とうとうめげて現状ODBCで作業
> しています。
>



-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.8.7 - Release Date: 2005/02/10




pgsql-jp メーリングリストの案内