1

私のシステムコンセプトはこれです。内部結合を使用して、異なるテーブルの列を表示しました。

SQLでinsertコマンドを一度に1つのテーブルにしか使用できないと思うので、苦労しています。

しかし、私のデータグリッドには、別のテーブルから呼び出された別の列が表示されます。

私のSQL構文の構造はどうなりますか? また、vb.net 2003でストアドプロシージャを呼び出します

誰かのアイデアに感謝します

これは私の SQL STORED PROC です

CREATE PROCEDURE AddToOfficeEquipmentProfile AS

INSERT INTO dbo.tblOfficeEquipmentProfile(OE_ID
                                        , Report_ID
                                        , OE_Category
                                        , OE_SubCategory
                                        , OE_Name
                                        , OE_User
                                        , OE_Brand
                                        , OE_Model
                                        , OE_Specs
                                        , OE_SerialNo
                                        , OE_PropertyNo
                                        , OE_Static_IP
                                        , OE_Vendor
                                        , OE_PurchaseDate
                                        , OE_WarrantyInclusiveYear
                                        , OE_WarrantyStatus
                                        , OE_Status
                                        , OE_Dept_Code
                                        , OE_Location_Code
                                        , OE_Remarks)
VALUES
  (DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT)
GO

これは私のVBコードです

Dim sqlconn As New SqlClient.SqlConnection
    sqlconn.ConnectionString = "server = SKPI-APPS1;" & _
    "Database = EOEMS;integrated security=true"

    Dim Command As SqlCommand = New SqlCommand
    Command.Connection = sqlconn
    Command.CommandText = "AddToOfficeEquipmentProfile"
    Command.CommandType = CommandType.StoredProcedure

    Dim sAdapter As SqlDataAdapter = New SqlDataAdapter(Command)
    Dim DataSet As DataSet = New DataSet(Command.CommandText)

    sAdapter.Fill(DataSet)
    DataGrid1.DataSource = DataSet.Tables(0)
    MsgBox(MsgBoxStyle.OKOnly, "YOU HAVE SUCCESSFULLY ADDED RECORDS TO THE TABLE")

を指すエラーを返します

 sAdapter.Fill(DataSet)

以下は、ストアド プロシージャを必要としない 2 番目のコードです。

    Dim adapter As New SqlDataAdapter
    Dim sql As String


    sql = "INSERT INTO tblOfficeEquipmentProfile(OE_ID, Report_ID, OE_Category, OE_SubCategory, OE_Name, OE_User, OE_Brand, OE_Model, OE_Specs, OE_SerialNo, OE_PropertyNo, OE_Static_IP, OE_Vendor, OE_PurchaseDate, OE_WarrantyInclusiveYear, OE_WarrantyStatus, OE_Status, OE_Dept_Code, OE_Location_Code, OE_Remarks)VALUES(DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT)"
    Try
        sqlconn.Open()
        adapter.InsertCommand = New SqlCommand(sql, sqlconn)
        adapter.InsertCommand.ExecuteNonQuery()
        MsgBox("Row inserted !! ")
    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try

しかし、まだ機能していません

4

1 に答える 1

1

あなたのコードはとても長いです、そして私が意味することは..

 Try
                    con = New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\notifdb.accdb")
                    Dim command As String
                    command = "INSERT INTO NFTB (NOTIF, EMP_NO, EMP_NAME, [POSITION]) VALUES (@NOTIF, @EMP_NO, @EMP_NAME, @POSITION)"
                    con.Open()
                    Dim cmd As OleDbCommand
                    cmd = New OleDbCommand(command, con)
                    cmd.Parameters.AddWithValue("@NOTIF", NOTIFTextBox.Text)
                    cmd.Parameters.AddWithValue("@EMP_NO", EMP_NOTextBox.Text)
                    cmd.Parameters.AddWithValue("@EMP_NAME", EMP_NAMETextBox.Text)
                    cmd.Parameters.AddWithValue("@POSITION", POSITIONTextBox.Text)
                    cmd.ExecuteNonQuery()
                Catch exceptionObject As Exception
                    MessageBox.Show(exceptionObject.Message)
                Finally
                    con.Close()
                End Try

挿入コードについて述べたばかりですが、自分で行う必要があります。また、SQL には DEFAULT 値がありません。列名の値を何かに変更してから、フォーム内のどのテキスト ボックスまたはフィールドがデータベースに入力されるかを示すパラメータを追加する必要があります。

于 2013-03-20T03:02:45.050 に答える