How would you connect to database using .NET?
Answer / Sanjay Kumar Joshi
To connect to a database using .NET, you can use the `SqlConnection` class for SQL Server. Here's an example:
```csharp
string connectionString = "Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword";
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
// Now you can perform database operations
}
```
Replace the `connectionString` values with your actual server address, database name, username, and password.
| Is This Answer Correct ? | 0 Yes | 0 No |
What we do with the object of ado.net dataset after using it?Can we dispose it or can we set it nothing?Is it must or not?
What are the Different layers in ADO.Net?
What is dataset and tell about its features. What are equivalent methods of previous, next etc. Of ADO in ADO.NET ?
How will you fill the gridview by using datatable object at runtime?
Can we connect two dataadapters to same data source using single connection at same time?
What are the different layers of ado.net?
How to add an aggregate column?
What are the different namespaces used in the project to connect the database?
What is untyped dataset?
Execute nonquery returns no. of afected rows.So if my stored procedure hav lot of select stmnt, delete stmnt, insert stmnt..then what does execute nonquery returns in this case?
Difference between ADO and ADO.Net
What are the advantages and drawbacks of using ado.net?
Visual Basic (800)
C Sharp (3816)
ASP.NET (3180)
VB.NET (461)
COM+ (79)
ADO.NET (717)
IIS (369)
MTS (11)
Crystal Reports (81)
BizTalk (89)
Dot Net (2435)
Exchange Server (362)
SharePoint (720)
WCF (340)
MS Office Microsoft (6963)
LINQ Language-Integrated Query (317)
WPF (371)
TypeScript (144)
Microsoft Related AllOther (311)