Click here to Skip to main content
15,894,410 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
here is my button click event code

protected void ButtonShowVideo_Click(object sender, EventArgs e)
{   
           
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
        SqlCommand  cmd1 = new SqlCommand();       
        conn.Open();
        cmd1.Connection = conn;
        cmd1.CommandType = CommandType.StoredProcedure;
        cmd1.CommandText = "Show_video16";
        cmd1.Parameters.Add("@ID", SqlDbType.Int).Value = TextBox1.Text;  
        SqlDataAdapter da = new SqlDataAdapter(cmd1);
        //cmd1.Parameters.Clear();             
        DataSet ds = new DataSet();
        DataTable dt = new DataTable();
        da.Fill(dt);
        Repeater1.DataSource = cmd1.ExecuteReader();
        Repeater1.DataBind();
        conn.Close();
}


The Stored Procedure is:
CREATE PROCEDURE [dbo].[show_video16]
(
		@ID int 
		
)
AS
declare @Video varbinary(max),
		@Video_Name nvarchar(50)
		
BEGIN
	select @Video=Video,@Video_Name =Video_Name from Videos where ID = @ID
END


I want to bind the data in repeater control during button click event
,but its not working,
Posted
Updated 8-Apr-11 2:23am
v3

You just need to do

Repeater1.DataSource = dt;

I don't think you need to do 'Repeater1.DataSource = cmd1.ExecuteReader();'

try this simple.
 
Share this answer
 
Definitely check over these lines...

DataSet ds = new DataSet();
DataTable dt = new DataTable();
da.Fill(dt);
Repeater1.DataSource = cmd1.ExecuteReader();


...which should be more like this...

DataSet ds = new DataSet();
da.Fill(ds);
if (ds.Tables.Count > 0)
{
    DataTable dt = ds.Tables[0];
    Repeater1.DataSource = dt;
    Repeater1.DataBind();
}


You shouldn't be binding to a IDataReader (result of ExecuteReader). Instead, fill your DataSet, get a DataTable from the results and bind to that
 
Share this answer
 
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
SqlCommand cmd1 = new SqlCommand(); 
DataTable dt = new DataTable();
cmd1.CommandType = CommandType.StoredProcedure;
cmd1.CommandText = "Show_video16";
cmd1.Parameters.Add("@ID", SqlDbType.Int).Value =convert.toInt32(TextBox1.Text); 
SqlDataAdapter da = new SqlDataAdapter();
da.selectedCommand=cmd1;
da.selectedCommand.connection=conn;
da.Fill(dt);
<big>Repeater1.DataSource = dt;</big>
Repeater1.DataBind();


I modified your code a little.Try With this.
 
Share this answer
 
I hope your query is right
But try this way


select Video,Video_Name from Videos where ID = @ID
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900