Click here to Skip to main content
15,901,001 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hai all i tried below code,in this i have this problem

1. my datalist is not loading that is it doesn't show any results ,wen i'm debugging it loads null.


my code is



string id = Session["id"].ToString();
string connn = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
SqlConnection con = new SqlConnection(connn);
con.Open();
string str = "select details,others from tb_userdata inner join tb_userlogin on tb_userdata.uidfromtb1=tb_userlogin.id where tb_userlogin.id=@id";

SqlCommand cmd = new SqlCommand(str, con);
cmd.Parameters.AddWithValue("@id", id);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);

and aspx page is


<asp:DataList runat="server" ID="ds">
<ItemTemplate>
<a href='<%# Eval("detials") %>'></a>
<a href='<%# Eval("others") %>'></a>

</ItemTemplate>


</asp:DataList>

can any one help me

Thanks and Regards
Posted
Comments
[no name] 22-Sep-13 17:13pm    
Did you spell "details" correctly in your real code? What is null? Why do you keep posting this over and over? Do you know how to debug your code?
Bryian Tan 22-Sep-13 18:01pm    
did you specify the DataSource and call the DataBind method?

yourDataListID.DataSource = ds.Tables[0];
yourDataListID.DataBind();

You use SqlDataAdapter for quite different thing. SqlDataAdapter is used for tablemapping. If I have understood well you want to select data from db and store it into a dataset, am I right? First, I don't know, what Data List is, but I thought DataSet perhaps. Use SqlDataReader for selecting from db and if you select one table, you can't use DataSet, but DataTable.

So use this code:
C#
string id = Session["id"].ToString();
string connn = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
SqlConnection con = new SqlConnection(connn);
con.Open();
string str = "select details,others from tb_userdata inner join tb_userlogin on tb_userdata.uidfromtb1=tb_userlogin.id where tb_userlogin.id=@id";
 
SqlCommand cmd = new SqlCommand(str, con);
cmd.Parameters.AddWithValue("@id", id);
SqlDataReader reader = new SqlDataReader(cmd, con);
DataTable table = new DataTable("UserData");
table.Columns.Add(new DataColumn("details", typeof(string)));
table.Columns.Add(new DataColumn("others", typeof(string)));
while (reader.Read)
{
   DataRow row = table.NewRow();
   row[0] = (String) reader.GetString(0);
   row[1] = (String) reader.GetString(1);
}
return table;


Pepin z Hané
 
Share this answer
 
I think you should check connection string
because you declared connection string as connn

and open connection for con connection string
 
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