質問

ここにいる誰もが、直接的または間接的に常に大きな助けになっています。そして、これが再び真実であることが大いに期待されています。

説明のため、ストアドプロシージャはFireBirdの下で実行されており、VBは.NETのものです

ストアドプロシージャがあります(以下の抜粋、重要なビットはWHEREです)

  select pn, pnm.description, si_number, entry_date, cmp_auto_key, 
  parts_flat_price,    labor_flat_price, misc_flat_price, woo_auto_key, 
  wwt_auto_key
  from parts_master pnm, wo_operation woo
 where pn like :i_pn || '%'
   and pnm.pnm_auto_key = woo.pnm_auto_key
  into :pn, :description, :work_order, :entry_date, :cmp, :parts_price,
       :labor_price, :misc_price, :woo, :wwt

以下のコードが続くパラメーターI_PNを使用するvbアプリからパラメーターを渡そうとしています(MyServerおよびMyPasswordの変数は、コードの前の部分から決定されます。)

    Try
        Dim FBConn As New FirebirdSql.Data.FirebirdClient.FbConnection()
        Dim FBCmd As FirebirdSql.Data.FirebirdClient.FbCommand

        Dim MyConnectionString As String
        MyConnectionString = _
        "datasource=" & MyServer & ";database=" & TextBox4.Text & "; & _
        user id=SYSDBA;password=" & MyPassword & ";initial catalog=;"

        FBConn = New FirebirdSql.Data.FirebirdClient. & _
        FbConnection(MyConnectionString)

        FBConn.Open()
        FBConn.CreateCommand.CommandType = CommandType.StoredProcedure

        FBCmd = New FirebirdSql.Data.FirebirdClient. & _
        FbCommand("WIP_COSTS", FBConn)

        FBCmd.CommandText = "WIP_COSTS"

        FBConn.CreateCommand.Parameters. & _
        Add("@I_PN", FirebirdSql.Data.FirebirdClient.FbDbType.Text). & _
        Value = TextBox1.Text

        Dim I_PN As Object = New Object()
        Me.WIP_COSTSTableAdapter.Fill(Me.WOCostDataSet.WIP_COSTS, @I_PN)
        FBConn.Close()
    Catch ex As System.Exception
        System.Windows.Forms.MessageBox.Show(ex.Message)
    End Try

VB.Appを実行してプログラムを実行しようとすると、次のエラーが表示されます:

  

動的SQLエラー
  SQLエラーコード= -206
  列不明
  I_PN
  1行目、29列目

そして、実際の問題が何であるかをはっきりとは言えません。つまり、私のロジックがVB側で間違っているのか、ストアドプロシージャで間違っているのかわかりません。

含まれているコーディングは、GoogleFuの長期滞在中に見つかったさまざまなコードで見つけた例からまとめられています。

VBで1か月または2か月以上の経験がある場合(私の場合とは異なり)、VBを一目で証明できます。私は確かにすべての種類のアドバイスを心から楽しんでいます。

いつものように、さらに質問がある場合は、できる限り回答します。

ありがとうございます。

Jasoomian

役に立ちましたか?

解決

少し考え直して、もう少し研究を重ねた結果、ようやくコードが機能するようになりました。

        Try

        ' Code for checking server location and required credentials

        Dim FBConn As FbConnection
        ' Dim FBAdapter As FbDataAdapter
        Dim MyConnectionString As String

        MyConnectionString = "datasource=" _
                        & MyServer & ";database=" _
                        & TextBox4.Text & ";user id=SYSDBA;password=" _
                        & MyPassword & ";initial catalog=;Charset=NONE"

        FBConn = New FbConnection(MyConnectionString)
        Dim FBCmd As New FbCommand("WIP_COSTS", FBConn)

        FBCmd.CommandType = CommandType.StoredProcedure
        FBCmd.Parameters.Add("@I_PN", FbDbType.VarChar, 40)
        FBCmd.Parameters("@I_PN").Value = TextBox1.Text.ToUpper


        Dim FBadapter As New FbDataAdapter(FBCmd)
        Dim dsResult As New DataSet
        FBadapter.Fill(dsResult)

        Me.WIP_COSTSDataGridView.DataSource = dsResult.Tables(0)

        Dim RecordCount As Integer
        RecordCount = Me.WIP_COSTSDataGridView.RowCount
        Label4.Text = RecordCount

    Catch ex As System.Exception
        System.Windows.Forms.MessageBox.Show _
        ("There was an error in generating the DataStream, " & _
        "please check the system credentials and try again. " &_ 
        "If the problem persists please contact your friendly " &_ 
        "local IT department.")
    End Try

    ' // end of line

また、実際のストアドプロシージャに変更を加える必要があると考えていましたが、これは間違っていることが判明しました。

コードはきれいではないかもしれません。エラー処理を改善するには、TRYブロックでさらに作業を行う必要があります。しかし、それは動作します。

参加してくれて、順調に進んでくれたすべての人に感謝します。

他のヒント

これを変更してみてください:

FBConn.CreateCommand.Parameters. & _
        Add("@I_PN", FirebirdSql.Data.FirebirdClient.FbDbType.Text). & _
        Value = TextBox1.Text

...これ:

FBCmd.Parameters.AddWithValue("@I_PN", TextBox1.Text)

基本的には、Connectionオブジェクトではなく、Commandオブジェクトにストアドプロシージャパラメーターを追加します。

アンドレイク、

これはストアドプロシージャ全体です。 Firebirdはバージョン1.5.3で、IbExpertバージョン2006.12.13、Dialect 3で記述されています

Begin
For
select pn, pnm.description, si_number, entry_date, cmp_auto_key, parts_flat_price,
       labor_flat_price, misc_flat_price, woo_auto_key, wwt_auto_key
  from parts_master pnm, wo_operation woo
 where pn like :i_pn || '%'
   and pnm.pnm_auto_key = woo.pnm_auto_key
  into :pn, :description, :work_order, :entry_date, :cmp, :parts_price,
       :labor_price, :misc_price, :woo, :wwt

Do begin
   labor_hours = null;
   work_type = null;
   parts_cost = null;
   labor_cost = null;
   ro_cost = null;
   customer = null;

   select company_name
     from companies
    where cmp_auto_key = :cmp
     into :customer;

   select work_type
     from wo_work_type
    where wwt_auto_key = :wwt
     into :work_type;

   select sum(sti.qty*stm.unit_cost)
     from stock_ti sti, stock stm, wo_bom wob
    where sti.wob_auto_key = wob.wob_auto_key
      and sti.stm_auto_key = stm.stm_auto_key
      and wob.woo_auto_key = :woo
      and sti.ti_type = 'I'
      and wob.activity <> 'Work Order'
      and wob.activity <> 'Repair'
     into :parts_cost;

   select sum(sti.qty*stm.unit_cost)
     from stock_ti sti, stock stm, wo_bom wob
    where sti.wob_auto_key = wob.wob_auto_key
      and sti.stm_auto_key = stm.stm_auto_key
      and wob.woo_auto_key = :woo
      and sti.ti_type = 'I'
      and wob.activity = 'Repair'
     into :ro_cost;

   select sum(wtl.hours*(wtl.fixed_overhead+wtl.variable_overhead+wtl.burden_rate)),
          sum(wtl.hours)
     from wo_task_labor wtl, wo_task wot
    where wtl.wot_auto_key = wot.wot_auto_key
      and wot.woo_auto_key = :woo
     into :labor_cost, :labor_hours;

   suspend;
   end
End

ハードコード-あなたの提案に対するコメントで返信しました。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top