开发者

System.Data.DataRowView exception when inserting row into SQL Server

开发者 https://www.devze.com 2023-01-17 01:33 出处:网络
Im getting an error No mapping exists from object type System.Data.DataRowView to a known managed provider native type every time i click my button.. here\'s my code..

Im getting an error No mapping exists from object type System.Data.DataRowView to a known managed provider native type every time i click my button.. here's my code..

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim insertCommand = <xml>
    INSERT INTO returns(
        Department, 
        Purpose, 
        Item_details, 
        Requested_by, 
        Approved_by, 
        ReturnDate
    ) 
    SELECT
        Department, 
        Purpose, 
        Items_Details, 
        Requested_by, 
        Approved_by, 
        Date 
    FROM borrow 
    WHERE ID = @BorrowID;
</xml>

    Dim param = cmd.CreateParameter()开发者_高级运维
    param.ParameterName = "@BorrowID"
    param.Value = ListBox1.SelectedValue


    cmd.CommandText = insertCommand.Value
    cmd.Parameters.Add(param)

    cmd.Connection = con
    Try
        con.Open()
        cmd.ExecuteNonQuery()

    Catch SqlExceptionErr As Exception
        MsgBox(SqlExceptionErr.ToString)


    Finally
        con.Close()
    End Try

End Sub


Borrow.Id needs to be bound to your ListBox.ValueMember.

0

精彩评论

暂无评论...
验证码 换一张
取 消