Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim objConn As New SqlConnection(strConnString)
Dim objCmd As SqlCommand
Dim strSQL As String
objConn.Open()
Dim dtAdapter As SqlDataAdapter
Dim dt As New DataTable
strSQL = "SELECT * FROM files WHERE Name = @sName"
dtAdapter = New SqlDataAdapter(strSQL, objConn)
objCmd = dtAdapter.SelectCommand
objCmd.Parameters.Add("@sName", SqlDbType.NVarChar).Value = Request.QueryString("Name")
dtAdapter.Fill(dt)
If dt.Rows.Count > 0 Then
Response.ContentType = dt.Rows(0)("FilesType").ToString()
Response.BinaryWrite(dt.Rows(0)("FilesName"))
End If
dt = Nothing
End Sub
แล้วก็ส่วนของหน้าหลัก Code (VB.NET)
Sub bindata()
Dim conn As New SqlConnection(strConnString)
'Dim objcmd As SqlCommand
Dim edate As String = Request("dateStart")
Dim edate2 As String = Request("dateEnd")
Dim expenddt As Date = Date.ParseExact(edate, "dd/MM/yyyy", System.Globalization.DateTimeFormatInfo.InvariantInfo)
Dim expenddt2 As Date = Date.ParseExact(edate2, "dd/MM/yyyy", System.Globalization.DateTimeFormatInfo.InvariantInfo)
Dim dt As New DataTable()
Dim query As String = " SELECT id, CONVERT(varchar(10),seen_dt,103) as seen_dt , seen_time, name_material, num_material, CONVERT(varchar(10),input_dt,103) as input_dt, input_time, lot, supplier, weight, obj, area, product_rm, status, files.FilesType, files.FilesName, files.Name, obj_tbl.nameIMG FROM obj_tbl INNER JOIN files ON files.Name = obj_tbl.nameIMG WHERE input_dt BETWEEN '" & expenddt & "' AND '" & expenddt2 & "' "
Dim objda As New SqlDataAdapter(query, conn)
conn.Open()
'objcmd = objda.SelectCommand
'objcmd.Parameters.Add("@sName", SqlDbType.Int).Value = Request.QueryString("Name") 'บรรทัดนี้ปัญหา
objda.Fill(dt)
If dt.Rows.Count > 0 Then
'Response.ContentType = dt.Rows(0)("FilesType").ToString()
'Response.BinaryWrite(dt.Rows(0)("FilesName"))
GridView11.DataSource = dt
GridView11.DataBind()
End If
conn.Close()
End Sub
และอีกอันหนึ่ง Code (VB.NET)
Protected Sub GridView11_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView11.RowDataBound
Dim ImgPic As Image = DirectCast(e.Row.FindControl("ImgPic"), Image)
If Not IsNothing(ImgPic) Then
'ImgPic.ImageUrl = e.Row.DataItem("Name")
ImgPic.ImageUrl = "ViewImg.aspx?Name= " & e.Row.DataItem("Name")
End If
End Sub