答案 0 :(得分:0)
非常感谢你们! 终于,我找到了一种打印datagridview的新方法
1) 首先,我像下面这样保存DataGridview
私人Sub btn_save_Click(发送者为对象,e作为EventArgs)处理btn_save.Click 试试
For i As Integer = 0 To dgvData.Rows.Count - 1
If CBool(dgvData.Rows(i).Cells("Column4").Value) Then
str = " insert into tbl_dummy(opd,name,testname,category,cost) values (" & TextBox1.Text & ",'" & TextBox2.Text & "','" & dgvData.Rows(i).Cells(0).Value & "','" + dgvData.Rows(i).Cells(1).Value & "','" + dgvData.Rows(i).Cells(2).Value & "') "
cmd = New SqlCommand(str, cn)
openconnection()
da.InsertCommand = cmd
da.InsertCommand.ExecuteNonQuery()
End If
Next
MessageBox.Show("Data Added Successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information)
closeconnection()
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
2)然后我从数据库中获取打印内容,通过这种方式,它可以提供所需的确切结果。