I would like to display content from sql table on a label.
I am using enities so I tried this code:
DBprojectModel1.DBprojectEntities1 context = new DBprojectModel1.DBprojectEntities1();
lbFullName.Text = from name in context.Pupils
where name.UserName.Contains(txtUser.text)
select name.FullName;
I am not sure how to write it correctly so the column FullName will be display in lbFullName.Text
and another question - if I want "txtUser.text" to be exactly the same like name.UserName (and not only contains) what should I write ?
thank you!
Satyapriya NayakPosted Feb 22, 2012, 2:02 PM
Try this...
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace aa
{
public partial class _Default : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string str;
SqlCommand com;
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(strConnString);
if (!IsPostBack)
{
con.Open();
str = "select * from table";
com = new SqlCommand(str, con);
SqlDataReader reader = com.ExecuteReader();
while (reader.Read())
{
Label1.Text = reader["Fullname"].ToString();
}
reader.Close();
con.Close();
}
}
}
}
Thanks