Reputation: 1294
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();
}
Upvotes: 2
Views: 2577
Reputation: 12884
You can use Strongly Typed DataSet File and then return data into your label
Upvotes: 0
Reputation: 3425
Framework 2.0 doesn't support LINQ! U can't use entity framework or LINQ in framework 2.0. Try framewerk 4.0. If not u have to write a query.
Upvotes: 0
Reputation: 39306
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
Upvotes: 3
Reputation: 857
You might want to find an ORM.
Linq to Sql and Entity Framework are a couple you can use out of the box in .Net.
Upvotes: 2
Reputation: 3425
Sorry I am not sure I understand your question, but I do not think there is a way to get 'any' data from DATABASE without querying. You may have to use a simple select query to return the data from a table or a stored procedure.
Upvotes: 0