Protected Sub imgbSearch_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles imgbSearch.Click
Dim Conn As New SqlConnection
Dim Com As New SqlCommand
Dim dr As New SqlDataAdapter
Dim ds As New DataSet
Dim dt As DataTable
'Dim strConnString As String
Dim strSQL As New StringBuilder
strSQL.Append(" SELECT tblTool.ToolID,tblCategory.CategoryName,tblTool.ReceiveDate,tblDepartment.DepartmentName,tblCompany.CompanyName ")
strSQL.Append(" FROM tblTool INNER JOIN tblCategory ON tblTool.CategoryID = tblCategory.CategoryID ")
strSQL.Append(" INNER JOIN tblDepartment ON tblTool.DepartmentID = tblDepartment.DepartmentID ")
strSQL.Append(" INNER JOIN tblCompany ON tblTool.CompanyID = tblCompany.CompanyID ")
strSQL.Append(" WHERE tblTool.ToolName LIKE '%" & txtSearch.Text & "%' ")
strSQL.Append(" AND tblTool.CategoryID LIKE '%" & ddlCategorySearch.SelectedValue & "%' ")
Com = New SqlCommand
With Com
.Connection = Conn
.CommandText = strSQL.ToString()
.CommandType = CommandType.Text
End With
dr.SelectCommand = Com
dr.Fill(ds, " MyDataTable")
dt = ds.Tables(0)
dr = Nothing
Conn.Close()
Conn = Nothing
Dim rpt As New ReportDocument()
rpt.Load(Server.MapPath("CrystalReport.rpt"))
rpt.SetDataSource(dt)
Me.CrystalReportViewer1.ReportSource = rpt
End Sub
'*** DataSet to DataTable ***'
Function CreateDsToDt() As DataTable
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 = "Server=localhost;UID=sa;PASSWORD=;database=mydatabase;Max Pool Size=400;Connect Timeout=600;"
strSQL = "SELECT * FROM customer"
objConn.ConnectionString = strConnString
With objCmd
.Connection = objConn
.CommandText = strSQL
.CommandType = CommandType.Text
End With
dtAdapter.SelectCommand = objCmd
dtAdapter.Fill(ds)
dt = ds.Tables(0)
dtAdapter = Nothing
objConn.Close()
objConn = Nothing
Return dt '*** Return DataTable ***'
End Function