سؤال

my system concept is this. im done displaying columns from different tables using inner join.

im finding a hard time because, i think that you can only use insert command in sql to one table at a time.

but my datagrid displays different columns called from different table.

how would be the structure of my sql syntax be? and also calling the stored procedure on vb.net 2003

thanks any ideas anyone

THIS IS MY 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

THIS IS MY VB CODE

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")

it returns error pointing to

 sAdapter.Fill(DataSet)

HERE IS MY SECOND CODE BELOW WITH NO STORED PROCEDURE NEEDED

    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

but still not working

هل كانت مفيدة؟

المحلول

Your code is so long, and by what i have mean is..

 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

i just said about the insert code, beside that you must do by your self. And SQL never have DEFAULT value, you must change the value of your column name to some thing, then add parameter to it that what textbox or field in your form that will be input to your database..

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top