1

在座的每一个人,一直都是那么大的帮助,无论是直接的还是间接的。寄希望于这再次成为现实。

为澄清起见,存储过程在 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
Column Unknown
I_PN
At Line 1, column 29

而且我不能完全确定实际问题是什么。意思是,我不知道我的逻辑是否在 VB 端或存储过程中不正确。

包含的任何编码都是从我发现的示例中与在 GoogleFu 长期逗留期间发现的各种代码位一起拼凑而成的。

任何拥有超过一两个月的 VB 经验(不像我)的人都可以只看一眼就可以证明——我的代码可能很糟糕而且格式不正确——当然不优雅,而且在操作上最有把握。我当然会张开双臂接受各种建议。

像往常一样,如果您还有其他问题,我会尽我所能回答。

再次感谢。

雅苏米安

4

3 回答 3

1

经过一番重新思考和更多研究,我终于让我的代码工作了..

        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 块中做更多的工作以更好地处理错误;但是,它有效。

感谢所有参与并帮助我走上正轨的人。

于 2009-03-26T16:43:21.220 回答
0

尝试改变这个:

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

...对此:

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

基本上,您希望将存储过程参数添加到 Command 对象,而不是 Connection 对象。

于 2009-03-18T02:45:40.197 回答
0

安德烈克,

这是整个存储过程。我们的 Firebird 是 1.5.3 版本,使用 IbExpert 版本 2006.12.13,方言 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

硬编码 - 我在评论中回复了您的建议。

于 2009-03-18T14:30:35.277 回答