Is there any way to retrive data from Database with out writing any sql query . I mean i want to read data into my label fileds with out writing any query in sqlcommand.Please anyone help me or tell me how can i do this in c# or vb.net
Update
protected void Page_Load(object sender, System.EventArgs e)
{
string connectionString = @"Data Source=Data Source=.\SQLEXPRESS;AttachDbFilename=E:\Test\Database.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
SqlConnection con = new SqlConnection(connectionString);
con.Open();
SqlCommand cmd = new SqlCommand("Select * from Test", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "Test");
GridView1.DataSource = ds;
GridView1.DataBind();
con.Close();
}
If you don’t want to write direct SQL queries, then another option is ORMs like:
Here’s a related post: https://stackoverflow.com/questions/3505/what-are-your-favorite-net-object-relational-mappers-orm
Depending on how much database interactions you need, you may find the few lines to execute a SQL command query directly easier. If you need to do quite a bit of DB interactions with objects then an ORM may be more productive for you.
Code samples are outside the scope of a question because you need to setup mappings etc… but here’s a getting started with tutorial: http://msdn.microsoft.com/en-us/library/bb386876.aspx