Dim rpt As New ReportDocument()
Dim directory As String = My.Application.Info.DirectoryPath
rpt.Load("C:\CrystalReport1.rpt")
rpt.SetParameterValue("dateSR1", Me.dtpStartSearch.Value.ToShortDateString)
Me.CrystalReportViewer1.ReportSource = rpt
Me.CrystalReportViewer1.Refresh()
Tag : .NET, Ms SQL Server 2008, VS 2010 (.NET 4.x)
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 strConnString, strSQL As String
strConnString = "Data Source=.\SQLEXPRESS;Initial Catalog=LAHWINFO;Integrated Security=True"
Dim sb As StringBuilder = New StringBuilder
sb.Remove(0, sb.Length())
sb.Append("SELECT * FROM TotalPrint")
sb.Append(" WHERE (DateSavePrint BETWEEN @date1 AND @date2)")
sb.Append(" SELECT SerialNo FROM TotalPrint")
sb.Append(" WHERE (SerialNo=@SerialNo)")
strSQL = sb.ToString()
objConn.ConnectionString = strConnString
With objCmd
.Parameters.Clear()
.Parameters.Add("@date1", SqlDbType.SmallDateTime).Value = dtpStartSearch.Value.ToShortDateString
.Parameters.Add("@date2", SqlDbType.SmallDateTime).Value = dtpEndSearch.Value.ToShortDateString
.Parameters.Add("@SerialNo", SqlDbType.NVarChar).Value = cboNamePrint.SelectedIndex
.CommandText = strSQL
.CommandType = CommandType.Text
.Connection = objConn
End With
dtAdapter.SelectCommand = objCmd
dtAdapter.Fill(ds, "myDataTable")
dt = ds.Tables(0)
dtAdapter = Nothing
objConn.Close()
objConn = Nothing
Dim rpt As New ReportDocument()
Dim directory As String = My.Application.Info.DirectoryPath
'rpt.Load(directory & "\myCrystalReport1.rpt")
rpt.Load("C:\CrystalReport2.rpt")
rpt.SetDataSource(dt)
Me.CrystalReportViewer1.ReportSource = rpt
Me.CrystalReportViewer1.Refresh()