VB EXPRESS-在VB.net中的DGV中访问中打印数据库 [英] VB EXPRESS-print a database in access in DGV in VB.net

查看:77
本文介绍了VB EXPRESS-在VB.net中的DGV中访问中打印数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在vb EXPRESS 2010年做了一个程序,我的数据库是Access.

i did a program in vb EXPRESS 2010, and my data base is Access.

我想从访问权限中打印出DataGridView中存在的数据.

i want to print the data that present in DataGridView from the access.

我尝试使用Crystal Report,但是我也使用了Print Form,但由于我有很多数据,它只给我提供了屏幕截图,而其余数据却不显示.

i tried using crystal report but it doesn't work also i used Print Form but because i've many data it gives me only screenshot and the remaining data are not appear.

我有许多需要水平和垂直打印的数据

i have many data that needs to printing horizontally and vertically 

这是我要打印的项目的示例代码...

here is a sample code of my project that i want to print...

导入 System.Data .OleDb

导入 System.Data . DataTable

Imports System.Data.DataTable

 

公共 课程 访问

Public Class visit

    昏暗索引 整数

    Dim index As Integer

    昏暗 connString 字符串 = "Provider = Microsoft.ACE.OLEDB.12.0; Data Source = C:\ Users \ sh \ Desktop \ FP \ Fproject.accdb"

    Dim connString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\sh\Desktop\FP\Fproject.accdb"

    昏暗 MyConn OleDbConnection

    Dim MyConn As OleDbConnection

    Dim da As OleDbDataAdapter

    Dim da As OleDbDataAdapter

    昏暗 ds 数据集

    Dim ds As DataSet

    昏暗表格 DataTableCollection

    Dim tables As DataTableCollection

    昏暗 source1 新建 BindingSource

    Dim source1 As New BindingSource

 

    公用 dr As OleDbDataReader

    Public dr As OleDbDataReader

 

    昏暗 vn,大众,vr 字符串

    Dim vn, vw, vr As String

 

    昏暗提供程序 字符串

    Dim provider As String

    昏暗 dataFile 字符串

    Dim dataFile As String

 

    昏暗 Sql 字符串

    Dim Sql As String

 

    昏暗 cmd2 新建 OleDb. OleDbCommand

    Dim cmd2 As New OleDb.OleDbCommand

 

    公用 myConnection OleDbConnection = 新建 OleDbConnection

    Public myConnection As OleDbConnection = New OleDbConnection

 

 

    私人 Sub visit_Load( ByVal 发​​件人 系统.对象 ByVal e As 系统. EventArgs ) 句柄 MyBase .加载

    Private Sub visit_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

       DateTimePicker1.Hide()

       MyConn = 新建 OleDbConnection

        MyConn = New OleDbConnection

       MyConn.ConnectionString = connString

       myConnection.ConnectionString = "Provider = Microsoft.ACE.OLEDB.12.0; Data Source = C:\ Users \ sh \ Desktop \ FP \ Fproject.accdb"

        myConnection.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\sh\Desktop\FP\Fproject.accdb"

       ds = 新建 数据集

        ds = New DataSet

      表= ds.Tables

       da = 新建 OleDbDataAdapter ("选择vname作为 _ الزائرة المسسمى _ الوظيفي سبب _ الزيارة التاريخ 来自[访客]"

        da = New OleDbDataAdapter("Select vname as اسم_الزائرة, vwork as المسسمى_الوظيفي, resv as سبب_الزيارة ,datev as التاريخ from [visitor]", MyConn)

       da.Fill(ds, 访客" )

        da.Fill(ds, "visitor")

       昏暗视图作为 新建 DataView (表(0))

        Dim view As New DataView(tables(0))

       source1.DataSource =视图

       DataGridView1.DataSource =视图

 

 

    结束

    End Sub

 

    私人 Button2_Click( ByVal 发​​件人 系统.对象 ByVal e As 系统. EventArgs ) 手柄 Button2.单击

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

       FirstForm .Show()

        FirstForm.Show()

       .Close()

        Me.Close()

    结束

    End Sub

 

    私人 Sub Timer1_Tick( ByVal 发​​件人 系统.对象 ByVal e As 系统. EventArgs ) 句柄 Timer1.Tick

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

       Label1.Text = Now.ToString(" dd/MMMM/yyyy-h:m:s tt" )

    结束

    End Sub

 

    私人 Button1_Click( ByVal 发​​件人 系统.对象 ByVal e As 系统. EventArgs ) 手柄 Button1.单击

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

       myConnection.Open()

       DateTimePicker1.Value =现在

       SQL = "插入访问者(vname,vwork,resv,datev)  VALUES(''" & .TextBox1.Text& ",," & .TextBox2.Text& "','" & .TextBox3.Text& "','" & .DateTimePicker1.Value.ToShortDateString&

        Sql = "INSERT INTO visitor(vname, vwork, resv, datev)  VALUES('" & Me.TextBox1.Text & "','" & Me.TextBox2.Text & "','" & Me.TextBox3.Text & "', '" & Me.DateTimePicker1.Value.ToShortDateString & "')"

       cmd2 = 新建 OleDb. OleDbCommand (Sql,myConnection)

        cmd2 = New OleDb.OleDbCommand(Sql, myConnection)

       cmd2.ExecuteNonQuery()

       MsgBox(" الإضافة بنجاح " MsgBoxStyle .信息, " الإضافة "

        MsgBox("تمت الإضافة بنجاح", MsgBoxStyle.Information, "تم الإضافة")

       TextBox1.Text = "

        TextBox1.Text = ""

       TextBox2.Text = "

        TextBox2.Text = ""

       TextBox3.Text = "

        TextBox3.Text = ""

       myConnection.Close()

       ds = 新建 数据集

        ds = New DataSet

      表= ds.Tables

       da = 新建 OleDbDataAdapter ("选择vname作为 _ الزائرة المسسمى _ الوظيفي سبب _ الزيارة التاريخ 来自[访客]"

        da = New OleDbDataAdapter("Select vname as اسم_الزائرة, vwork as المسسمى_الوظيفي, resv as سبب_الزيارة ,datev as التاريخ from [visitor]", MyConn)

       da.Fill(ds, 访客" )

        da.Fill(ds, "visitor")

       视图 新建 DataView (表(0))

        Dim view As New DataView(tables(0))

       source1.DataSource =视图

       DataGridView1.DataSource =视图

    结束

    End Sub

 

  

结束

End Class

谢谢

推荐答案

法蒂玛246,

Hi Fatimah246,

感谢您在MSDN论坛中发帖.

Thank you for posting in MSDN forum.

根据您的描述,我建议您可以使用 PageSetupDialog 更改打印设置.当您调用PageSetupDialog.ShowDialog()时,将出现一个对话框.

According to your description, I suggest that you could use PageSetupDialog to change the print settings. A dialog box will appear when you call PageSetupDialog.ShowDialog().

您还可以通过设置PrintDocument的DefaultPageSettings属性来设置横向格式.

You could also set the landscape format by set the PrintDocument's DefaultPageSettings property.

有关更多信息,您可以参考MSDN库: https://msdn.microsoft.com/zh-CN/library/ms404294(v=vs.100).aspx

For more information you could refer MSDN library: https://msdn.microsoft.com/en-us/library/ms404294(v=vs.100).aspx

我发现了关于

And I found this thread about Printing preview and print in vb.net applications.

希望有帮助.

最好的问候,

张娜达


这篇关于VB EXPRESS-在VB.net中的DGV中访问中打印数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆