cant bind data from sql server 2008 r2 to gridview through vs2010
Hi
i have a requirement , i want to display the users in a webpart.
i have done some coding but it is not working.
i want to display the data from sql server table to a grid view in vs2010 through a web part
my code is
protected void Button1_Click(object sender, EventArgs e)
{
SqlCommand cmd;
SqlDataAdapter da;
DataSet ds = new DataSet();
SqlConnection con = new SqlConnection("Data Source=spsrv;Initial Catalog=GrandCacheCodeDB;User Id=sa;Password=Pass1234;Integrated Security=True");
con.Open();
string str = ("select UserId,UserName from aspnet_Users ");
cmd = new SqlCommand(str, con);
da = new SqlDataAdapter(cmd);
da.Fill(ds, "aspnet_Users");
gv.DataSource = ds.Tables[0];
gv.DataBind();
con.Close();
}
}
}
the data is not geting binded to the gridview can u halp me out