Domanda

Tutti qui sono sempre stati di grande aiuto, direttamente o indirettamente. Ed è con grande speranza che questo, ancora una volta, suoni vero.

Per motivi di chiarezza, la Stored Procedure è in esecuzione su FireBird e il VB è della varietà .NET

Ho una procedura memorizzata (estratto di seguito, un bit importante è DOVE)

  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

Sto cercando di passare un parametro da un'app vb, che utilizza il parametro I_PN, il cui codice segue di seguito (Le variabili per MyServer e MyPassword sono determinate da una parte precedente del codice.)

    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

Quando eseguo VB.App e provo ad eseguire il programma, ottengo il seguente errore:

  

Errore SQL dinamico
  Codice di errore SQL = -206
  Colonna sconosciuta
  I_PN
  Alla riga 1, colonna 29

E non riesco proprio a capire quale sia il vero problema. Significato, non so se la mia logica non è corretta sul lato VB o sulla Stored Procedure.

Qualsiasi codifica inclusa viene raggruppata dagli esempi che ho trovato con vari frammenti di codice trovati durante lunghi soggiorni di GoogleFu.

Come chiunque abbia più di un mese o due di esperienza (a differenza di me) con VB può attestare con una semplice occhiata - il mio codice è probabilmente piuttosto scadente e non ben formato - certamente non elegante e sicuramente operativo. Certamente intratterò tutti i gusti di consigli a braccia aperte.

Come al solito, se hai ulteriori domande, risponderò al meglio delle mie capacità.

Grazie ancora.

Jasoomian

È stato utile?

Soluzione

Dopo un po 'di ripensamento e un po' più di ricerca, finalmente ho fatto funzionare il mio codice ..

        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

Avevo anche pensato che avrei dovuto apportare modifiche all'effettiva procedura memorizzata, ma si è rivelato errato.

Il codice potrebbe non essere carino, e ho bisogno di fare più lavoro nel mio blocco TRY per una migliore gestione degli errori; ma funziona.

Grazie a tutti coloro che sono intervenuti e mi hanno aiutato a salire in pista.

Altri suggerimenti

Prova a cambiare questo:

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

... a questo:

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

Fondamentalmente, si desidera aggiungere i parametri della procedura memorizzata all'oggetto Command, non all'oggetto Connection.

Andreik,

Ecco l'intera procedura memorizzata. E il nostro Firebird è la versione 1.5.3, scritta con IbExpert versione 2006.12.13, dialetto 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

Hardcode: ho risposto nei commenti al tuo suggerimento.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top