micah says:
public
void
Getgallery(
string
username)
{
string
str = ConfigurationManager.ConnectionStrings[
"DB"
].ConnectionString;
string
getADPOST =
"GetNewrecord"
;
using
(SqlConnection con =
new
SqlConnection(str))
{
con.Open();
using
(SqlCommand cmd =
new
SqlCommand(getADPOST, con))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue(
"@UserName"
, Session[
"userName"
]);
SqlDataAdapter da =
new
SqlDataAdapter(cmd);
DataTable dt =
new
DataTable();
dt.Columns.AddRange(
new
DataColumn[3] {
new
DataColumn(
"Id"
,
typeof
(
int
)),
new
DataColumn(
"UserName"
,
typeof
(
string
)),
new
DataColumn(
"ImageName"
,
typeof
(
string
)) });
var result = dt.AsEnumerable().Take(5);
DataTable ds = dt.Clone();
foreach
(DataRow dr
in
result)
{
ds.Rows.Add(dr[
"Id"
], dr[
"ImageName"
]);
}
Repeater1.DataSource = ds;
Repeater1.DataBind();
}
Replace with below code.
public void Getgallery(string username)
{
// int followerid;
// int followingid;
string str = ConfigurationManager.ConnectionStrings["DB"].ConnectionString;
string getADPOST = "GetNewrecord";
using (SqlConnection con = new SqlConnection(str))
{
con.Open();
using (SqlCommand cmd = new SqlCommand(getADPOST, con))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@UserName", Session["userName"]);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
var result = dt.AsEnumerable().Take(5);
DataTable ds = dt.Clone();
foreach (DataRow dr in result)
{
ds.Rows.Add(dr["Id"], dr["ImageName"]); //Pass proper column name
}
Repeater1.DataSource = ds;
Repeater1.DataBind();
}
}
}