在我的code。使用eval函数后面? [英] Using Eval function in my code behind?

查看:168
本文介绍了在我的code。使用eval函数后面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的code:

Partial Class VideoPlayer
Inherits System.Web.UI.Page
Protected strFileName As String

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    Dim con As New OleDbConnection
    Dim dbProvider As String
    Dim dbSource As String
    Dim vidID As Integer = Integer.Parse(Request.QueryString("ID"))

    dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
    dbSource = "Data Source = |DataDirectory|/webvideos.mdb"

    con.ConnectionString = dbProvider & dbSource

    con.Open()
    Dim strSQL As String = "SELECT * FROM Videos WHERE ID=" & vidID
    strFileName = "videos/TrainingVideos/" & Eval("Filename")

    con.Close()
End Sub

End Class

所以,当我运行code,它告诉我不能在我的字符串运行评估和演示。我缺少什么?

So when I run the code, it tells me it can't run Eval on my string. What am I missing?

推荐答案

评估将在.aspx code与DataBoundControl工作。

Eval will work in your .aspx code with a DataBoundControl.

当在code-的背后,要设置ConnectionString,则SQL查询和其他变量,但你实际上并没有执行查询。

When in code-behind, you are setting up the connectionstring, sql query and other variables but you are not actually executing the query.

所以你的code应该类似如下:

So your code should be something like below:

    Dim con As New OleDbConnection
    Dim dbProvider As String
    Dim dbSource As String
    Dim vidID As Integer = Integer.Parse(Request.QueryString("ID"))

    dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
    dbSource = "Data Source = |DataDirectory|/webvideos.mdb"

    con.ConnectionString = dbProvider & dbSource

    con.Open()
    Dim strSQL As String = "SELECT * FROM Videos WHERE ID=" & vidID

    //Create an OleDbCommand object.
    //Pass in the SQL query and the OleDbConnection object
    Dim cmd As OleDbCommand = New OleDbCommand(strSQL, con)

    //Execute the command 
    Dim reader As OleDbDataReader = cmd.ExecuteReader 

    //Read the first record from the reader
    reader.Read()
    strFileName = "videos\TrainingVideos\" & reader(1)
    con.Close()

这篇关于在我的code。使用eval函数后面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆