مشكلة حقن معلمة 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
وأنا أحاول أن تمرير معلمة من التطبيق الخامس باء، يستخدم المعلمة 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، أو، على إجراء مخزن.
ووkludged أي الترميز المضمنة معا من الأمثلة لقد وجدت مع مختلف أجزاء من التعليمات البرمجية التي عثر عليها أثناء يمكث طويلة من GoogleFu.
وكما أي شخص لأكثر من شهر أو شهرين من الخبرة (على عكس لي) مع 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
وترميز ثابت - I ردت في التعليقات على اقتراحكم
.