System.Data.DataRowView异常时,插入行到SQL Server异常、Data、System、DataRowView

由网友(夜幕下浅浅的笑)分享简介:即时得到一个错误时不存在映射从对象类型System.Data.DataRowView为已知的托管提供原始类型,每次我点击我的按钮......这是我的code .. 私人小组的button1_Click(BYVAL发件人为System.Object的,BYVALË作为System.EventArgs)把手Button1....

即时得到一个错误时不存在映射从对象类型System.Data.DataRowView为已知的托管提供原始类型,每次我点击我的按钮......这是我的code ..

 私人小组的button1_Click(BYVAL发件人为System.Object的,BYVALË作为System.EventArgs)把手Button1.Click

    昏暗的InsertCommand =< XML>
    INSERT INTO回报率(
        部门,
        目的,
        Item_details,
        被要求,
        由通过,
        ReturnDate
    )
    选择
        部门,
        目的,
        Items_Details,
        被要求,
        由通过,
        日期
    从借
    其中id = @BorrowID;
< / XML>

    昏暗的参数= cmd.CreateParameter()
    param.ParameterName =@BorrowID
    param.Value = ListBox1.SelectedValue


    cmd.CommandText = insertCommand.Value
    cmd.Parameters.Add(参数)

    cmd.Connection = CON
    尝试
        con.Open()
        cmd.ExecuteNonQuery()

    捕捉SqlExceptionErr作为例外
        MSGBOX(SqlExceptionErr.ToString)


    最后
        con.Close()
    结束尝试

结束小组
 

解决方案

Borrow.Id需要绑定到你的ListBox.ValueMember。

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
System.Data.SqlClient.SqlException未经处理的异常在 System.Data.dll 中发生 其他信息 用户登录失败

解决方案

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

阅读全文

相关推荐

最新文章