Friday, July 31, 2009

How to connect database to form using asp & c#?

pls can any body tell me , how to connect database to form using asp %26amp; c#

How to connect database to form using asp %26amp; c#?
In ASP.Net you could connect to database in two ways; either declaratively or programmatically.





In declarative method, you could use a SqlDataSource control (a %26lt;asp:SqlDataSource%26gt; tag) to define a connection to the database with a proper ConnectionString, provider and at lease one of the Select, Update, Insert or Delete commands. You could also use a data-bound control such as DropDownList, GridView, or Repeater, … to automatically retrieve data from database or even update the data. In this case, you wouldn’t need to write a single line of programming code in your .cs source file.





In programmatic method, you would use a namespace (System.Data.SqlClient) with a set of classes like SqlConnection and SqlCommand to connect and interact with the data base. Then you would use query commands of SqlCommand object to execute query and non-query transactions on database.





In both case you could use your Web.Config file to define your SQL connection string.





I hope it has been a short useful hint. Good luck.
Reply:The simplest way is to use ADO.Net objects.





That's a subject that's way to complex to explain here.





Go to your local Border's and look through some of the ADO.Net books there. You may even be able to get them from your local library.
Reply:u've to write the following codes within prog.





SqlConnection con = new SqlConnection("Server=...write the server name here...");


SqlCommand com = new SqlCommand();


SqlDataAdapter da = new SqlDataAdapter();


DataSet ds = new DataSet();





Then select a datagrid %26amp; transfer the entire database %26amp; place there, okay ?

hawthorn

No comments:

Post a Comment