Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiview - embed object based on SQL

Status
Not open for further replies.

R7Dave

Programmer
Oct 31, 2007
181
US
Hello

I am trying to embed YouTube video inbto my ASP.net page using a multiview.

I want to query a SQL database to pick which embed code to use

The source looks like this

<asp:View ID="View5" runat="server">
<object type="application/x-shockwave-flash"
data=" width=800 height=650><param name="movie"
value=" /><param name="FlashVars"
value="playerMode=embedded" /></object>
</asp:View>

This works fine, but I want each user to login and have their own YouTube player. I want to pull what is between the object tags from SQL and have it displayed

How can I change the object tag at runtime based on SQL?

So something like

Bob logs in

<object> Bobs YouTube embed code </object

Joe logs in

<object> Joes YouTube embed code </object

Is there a way to do this in the DataBinding event of the view?

Thanks in advance
Dave
 
Code:
<object type="application/x-shockwave-flash"
data='<%=youTube.Data%>' width=800 height=650><param name="movie"
value='<%=youTube.Value%>' /><param name="FlashVars"
value="playerMode=embedded" /></object>
Code:
public YouTubeDto youTube;

protected void Page_Load(object sender, EventArgs e)
{
  youTube = get_youtube_data_for(Identity);
}
Code:
public class YouTubeDto
{
    public string Data {get;set;}
    public string Value {get;set;}
}
Identity will give you the current users credentials including their username, assuming you are using one of the built in authentication methods.

get_youtube_data_for() is your code to query the database and load a YouTubeDto object.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
I think I got it - thank you for posting Jason.

Thanks
Dave
 
Hello again - I'm receiving an error

Public member 'Data' on type 'String' not found

I'm writing in VB

markup
Code:
<object type="application/x-shockwave-flash"
data='<%=youTube.Data%>' width="800" height="650"><param name="movie"
value='<%=youTube.Data%>' /><param name="FlashVars"
value="playerMode=embedded" /></object>

Code:
Imports System.Data 
Partial Class Member
   Inherits System.Web.UI.Page
   Protected WithEvents conn As New SqlClient.SqlConnection 

Public youTube

Code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            MultiView1.ActiveViewIndex = 0
            RadioButtonList1.SelectedIndex = 0
            youTube = YouTubeDto2()
        End If

Code:
Public Function YouTubeDto2()
        conn.Close()

        Dim Data As String
        Data = ""

        conn.ConnectionString = "data source=(local)" & ";initial catalog=xxxx;integrated security=SSPI;persist security info=False;;packet size=4096"
        Dim strSQL As String = "select YouTubeValue from GG_YOUTUBE where userid='" & "DB123'"
        Dim Cmd As New SqlClient.SqlCommand 
        Cmd.Connection = conn               
        Cmd.CommandText = strSQL            
        Dim Sql_DA_Request As New SqlClient.SqlDataAdapter         Sql_DA_Request.SelectCommand = Cmd 
conn.Open()                         
        Dim Tbl_Request As New DataTable   
        Sql_DA_Request.Fill(Tbl_Request)            GV_YouTube.DataSource = Tbl_Request  
        GV_YouTube.DataBind()        
        If Tbl_Request.Rows.Count > 0 Then  
            lbl_no_records.Visible = False          
Else
            lbl_no_records.Visible = True   
        End If
        Dim myDataReader As SqlClient.SqlDataReader
        myDataReader = Cmd.ExecuteReader
        myDataReader.Read()
        Data = myDataReader("YouTubeValue").ToString
        conn.Close()

        Return Data
        Data = "[URL unfurl="true"]http://www.youtube.com/cp/vjVQa1PpcFPuYA-QdSdvEtBHa43Je2EFhjNc2ShG1pM="[/URL]


    End Function

I think I am messing up with creating the object but I don't understand. Thanks for any help.

Dave
 
The last line after "Return Data" shouldn't have been included in my post


The error points to the code below

Code:
<object type="application/x-shockwave-flash"
data='<%=youTube.Data%>' width="800" height="650"><param name="movie"
value='<%=youTube.Data%>' /><param name="FlashVars"
value="playerMode=embedded" /></object>

Public member 'Data' on type 'String' not found is the error message - what is the correct VB syntax for declaring "Data"?

Thanks
Dave


 
data is a local property with the youtubedto2() method. I don't see where you define the youtube variable.

looking at your code you should be able to do this
Code:
<object type="application/x-shockwave-flash"
data='<%=YouTubeDto2()%>' width="800" height="650"><param name="movie"
value='<%=YouTubeDto2()%>' /><param name="FlashVars"
value="playerMode=embedded" /></object>
Code:
Public Function YouTubeDto2()
        conn.Close()

        Dim Data As String
        Data = ""

        conn.ConnectionString = "data source=(local)" & ";initial catalog=xxxx;integrated security=SSPI;persist security info=False;;packet size=4096"
        Dim strSQL As String = "select YouTubeValue from GG_YOUTUBE where userid='" & "DB123'"
        Dim Cmd As New SqlClient.SqlCommand
        Cmd.Connection = conn               
        Cmd.CommandText = strSQL            
        Dim Sql_DA_Request As New SqlClient.SqlDataAdapter         Sql_DA_Request.SelectCommand = Cmd
conn.Open()                         
        Dim Tbl_Request As New DataTable   
        Sql_DA_Request.Fill(Tbl_Request)            GV_YouTube.DataSource = Tbl_Request  
        GV_YouTube.DataBind()        
        If Tbl_Request.Rows.Count > 0 Then  
            lbl_no_records.Visible = False          
Else
            lbl_no_records.Visible = True   
        End If
        Dim myDataReader As SqlClient.SqlDataReader
        myDataReader = Cmd.ExecuteReader
        myDataReader.Read()
        Data = myDataReader("YouTubeValue").ToString
        conn.Close()
        Return Data
    End Function

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Hi Jason

"I don't see where you define the youtube variable"

- that is the part I don't get - what is the syntax? Based on this code, where would YouTube go?

I put "Public youTube" in my second code window above

then "youTube = YouTubeDto2()" on the page load

I'm not as familiar with this part - is this where my error is? How do I define the youtube variable correctly?

Thanks
Dave
 
this was my thought
Code:
public class YouTube
{
  public string LinkToVideo {get; private set;}
  public YouTube(string url)
  {
       LinkToVideo = url;
  }
}

public class YouTubeRepository
{
   public YouTube Get(int id)
   {
       //query database by id for link
       var string url = (string)row["name of column in row"];
       return new YouTube(url);
   }
}
Code:
<object type="application/x-shockwave-flash"
data='<%=youTube.LinkToVideo%>' width="800" height="650"><param name="movie"
value='<%=youTube.LinkToVideo%>' /><param name="FlashVars"
value="playerMode=embedded" /></object>
Code:
public YouTube youTube {get; private set;}

public void Page_Load(object sender, EventArgs e)
{
      var id = GetIdFromSomeWhere();
      youTube = new YouTubeRepository().Get(id);
}

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Thanks Jason - I will try that - have a good weekend.

Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top