读取:
<asp:TemplateColumn HeaderText="Image">
<ItemTemplate>
<asp:Image
Width="150" Height="125"
ImageUrl='<%# FormatURL(DataBinder.Eval(Container.DataItem, "PersonID")) %>'
Runat=server />
</ItemTemplate>
</asp:TemplateColumn>
And the method FormatURL (A Server side Function) is as follows. Function FormatURL(strArgument) as String
Return ("readrealimage.aspx?id=" & strArgument)
End Function And the method FormatURL (A Server side Function) is as follows. Function FormatURL(strArgument) as String
Return ("readrealimage.aspx?id=" & strArgument)
End Function
显示:
Public Sub Page_Load(sender As Object, e As EventArgs) Dim strImageID as String = Request.QueryString("id") ' Create Instance of Connection and Command Object
Dim myConnection As New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Dim myCommand As New SqlCommand("Select PersonImageType, PersonImage from das_person_real_images Where PersonID=" & strImageID, myConnection) ' I have used the select statement. But it would be much much better, if you
'could write a small stored procedure which contains the above sql statement.
' Mark the Command as a SPROC (in case, if you wrote the stored procedure
'myCommand.CommandType = CommandType.StoredProcedure Try
myConnection.Open()
Dim myDataReader as SqlDataReader
myDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
Do While (myDataReader.Read())
Response.ContentType = myDataReader.Item("PersonImageType")
Response.BinaryWrite(myDataReader.Item("PersonImage"))
Loop
myConnection.Close()
Catch SQLexc As SqlException End Try End Sub
<asp:TemplateColumn HeaderText="Image">
<ItemTemplate>
<asp:Image
Width="150" Height="125"
ImageUrl='<%# FormatURL(DataBinder.Eval(Container.DataItem, "PersonID")) %>'
Runat=server />
</ItemTemplate>
</asp:TemplateColumn>
And the method FormatURL (A Server side Function) is as follows. Function FormatURL(strArgument) as String
Return ("readrealimage.aspx?id=" & strArgument)
End Function And the method FormatURL (A Server side Function) is as follows. Function FormatURL(strArgument) as String
Return ("readrealimage.aspx?id=" & strArgument)
End Function
显示:
Public Sub Page_Load(sender As Object, e As EventArgs) Dim strImageID as String = Request.QueryString("id") ' Create Instance of Connection and Command Object
Dim myConnection As New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Dim myCommand As New SqlCommand("Select PersonImageType, PersonImage from das_person_real_images Where PersonID=" & strImageID, myConnection) ' I have used the select statement. But it would be much much better, if you
'could write a small stored procedure which contains the above sql statement.
' Mark the Command as a SPROC (in case, if you wrote the stored procedure
'myCommand.CommandType = CommandType.StoredProcedure Try
myConnection.Open()
Dim myDataReader as SqlDataReader
myDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
Do While (myDataReader.Read())
Response.ContentType = myDataReader.Item("PersonImageType")
Response.BinaryWrite(myDataReader.Item("PersonImage"))
Loop
myConnection.Close()
Catch SQLexc As SqlException End Try End Sub
if (VbyteFile==null){
//
}
else
{
//
}
在查询分析器里 SELECT * FROM YourTable WHERE 图字段 IS NOT NULL楼上的不用这么兴师动众哈