Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim objConn As New SqlConnection
Dim objCmd As New SqlCommand
Dim dtAdapter As New SqlDataAdapter
Dim ds As New DataSet
Dim dt As DataTable
Dim print As New printchq
Dim strConnString, strSQL As String
strConnString = "Data Source=KWAN-PC\SQLEXPRESS;Initial Catalog=Chqprint;Integrated Security=True"
strSQL = "SELECT * FROM orders WHERE or_id = '" & Me.TextBox1.Text & "'"
objConn.ConnectionString = strConnString
With objCmd
.Connection = objConn
.CommandText = strSQL
.CommandType = CommandType.Text
End With
dtAdapter.SelectCommand = objCmd
dtAdapter.Fill(ds, "Datareorder")
dt = ds.Tables(0)
dtAdapter = Nothing
objConn.Close()
objConn = Nothing
print.Show()
End Sub
code ตัว แสดง report Code (VB.NET)
ผมไม่ได้เขียนรัยลงไปครับ ผมไม่รู้เขียนยังไง อิอิ
Tag : .NET, Ms SQL Server 2008, Crystal Report, Win (Windows App), VB.NET, VS 2010 (.NET 4.x)
Dim rpt As New ReportDocument()
Dim directory As String = My.Application.Info.DirectoryPath
rpt.Load("D:\cqhprint\cqhprint\ChqReport1.rpt")
rpt.SetDataSource(dt)
Me.CrystalReportViewer2.ReportSource = rpt
Me.CrystalReportViewer2.Refresh()