从datagridview打印选定的行错误

时间:2013-12-14 12:19:56

标签: vb.net printing datagridview

我正在使用此代码从datagridview&中打印选定的行我收到此错误(无法对System.Int32和System.String执行'='操作。)

Me.salesTableAdapter.Fill(Me.ordersDataSet.sales)
    Me.ordersDataSet.sales.DefaultView.RowFilter = "id='" &
    Form1.SalesDataGridView.Item(1, Form1.SalesDataGridView.CurrentRow.Index).Value &
    "'"
    salesBindingSource.DataSource = Me.ordersDataSet.sales.DefaultView
    Me.ReportViewer1.RefreshReport()

1 个答案:

答案 0 :(得分:0)

放弃''

Me.ordersDataSet.sales.DefaultView.RowFilter = String.Format("id={0}", Form1.SalesDataGridView.Item(1, Form1.SalesDataGridView.CurrentRow.Index).Value)

如果列/字段可以为空,则可以执行以下操作:

Dim value As Object = Me.SalesDataGridView.Item(1, Me.SalesDataGridView.CurrentRow.Index).Value

If ((value Is Nothing) OrElse ((TypeOf value Is DBNull) OrElse ((TypeOf value Is System.Data.SqlTypes.INullable) AndAlso DirectCast(value, System.Data.SqlTypes.INullable).IsNull))) Then
    Me.ordersDataSet.sales.DefaultView.RowFilter = "[id] IS NULL"
Else
    Dim id As Integer = System.Convert.ToInt32(value)
    Me.ordersDataSet.sales.DefaultView.RowFilter = String.Format("[id]={0}", id)
End If