问题注入VB参数到存储过程中(火鸟)
-
19-08-2019 - |
题
在这里每个人都一直如此巨大的帮助,无论是直接或间接的影响。它是与盛大希望这,再次,真正的戒指。
有关澄清的缘故,所存储的程序是火鸟下运行和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
我试图通过从VB应用程序的参数,使用该参数I_PN,其中下面跟随代码(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的长逗留发现的码的各个位,发现实例kludged在一起。
由于与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)
基本上,要存储过程的参数添加到命令对象,而不是连接对象。
Andreik,
下面是整个存储过程。而我们的火鸟是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
硬编码 - 我在评论中回复您的建议
。