通过Windows窗体

时间:2017-05-01 11:11:47

标签: vb.net visual-studio oracle-sqldeveloper

我正在编写一个小型Windows应用程序,我的任务是允许系统用户通过存储过程添加,删除,更新和查看记录。我能够查看和更新​​现有记录,但我无法正确添加记录。添加功能添加PartNo和Quantity但它不添加PartName或Manufacturer。在我添加新零件后刷新表格时它们显示为零。这是我下面的Add sub_routine和我的存储过程。我正在使用Oracle SQL Developer和Visual Studio 2015.我的语法是正确的还是我遗漏了使add方法排除PartName和Manufacturer的东西。

//将记录添加到PARTS表的子例程

Private Sub addPart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addPart.Click

        Dim cmd As New OracleCommand("Garage.ADDPART", Form1.Connect())
        cmd.CommandType = CommandType.StoredProcedure
        cmd.Parameters.Add("@PARTNO", Val(txtAddPartNo.Text))
        cmd.Parameters.Add("@PARTNAME", Val(txtAddPartName.Text))
        cmd.Parameters.Add("@MANUFACTURER", Val(txtAddManufacturer.Text))
        cmd.Parameters.Add("@QUANTITY", Val(txtAddQuantity.Text))
        Try
            cmd.ExecuteNonQuery()
            MsgBox("Record Added")
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

// ADDPART存储过程

create or replace procedure ADDPART(
new_partno PART.PARTNO%type,
new_partname PART.PARTNAME%type,
new_manufacturer PART.MANUFACTURER%type,
new_quantity PART.QUANTITY%type)
as
begin insert into PART
(PARTNO, PARTNAME, MANUFACTURER, QUANTITY)
values
(new_partno, new_partname, new_manufacturer, new_quantity);
Commit;
exception
when dup_val_on_index then
raise_application_error(-20001, 'Product already exists');
when others then
raise_application_error(-20011, sqlerrm);
END ADDPART;

1 个答案:

答案 0 :(得分:0)

鉴于partname和manufacturer的表列是varchar2,请将对此存储过程的过程调用更改为:

Private Sub addPart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addPart.Click

    Dim cmd As New OracleCommand("Garage.ADDPART", Form1.Connect())
    cmd.CommandType = CommandType.StoredProcedure
    cmd.Parameters.Add("@PARTNO", Val(txtAddPartNo.Text))
    cmd.Parameters.Add("@PARTNAME", txtAddPartName.Text)
    cmd.Parameters.Add("@MANUFACTURER", txtAddManufacturer.Text)
    cmd.Parameters.Add("@QUANTITY", Val(txtAddQuantity.Text))
    Try
        cmd.ExecuteNonQuery()
        MsgBox("Record Added")
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
End Sub

val()txtAddPartName.text移除txtAddManufacturer.text功能。