Click here to Skip to main content
15,509,914 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am studing webforms and i went throught two controls the first one is the sqldatasource and the other is the objectdatasource but i am a liite confused about which one is mostly used in web form

on the other hand developers says that sqldatasource is bad because i can make conflicts in schemas spicially if the project is very big

can any one help me in that

What I have tried:

read more about both controls the sqldatasource and the objectdatasource
Updated 17-Mar-20 5:32am

SqlDataSource is used when you are connecting to a Microsoft Sql Server. The ObjectDataSource is used when connecting to servers that are not Microsoft Sql server.

That is the basic difference.
Share this answer
Richard Deeming 17-Mar-20 10:26am    
Not quite.

SqlDataSource is used if you're connecting directly to SQL. ObjectDataSource is used if you're calling custom code to load the data.
The SqlDataSource control connects directly to a SQL Server database. The main problem with it is that you end up embedding your queries within the markup of your pages, which makes it difficult to keep your code clean.

Querying Data with the SqlDataSource Control (VB) | Microsoft Docs[^]

The ObjectDataSource control calls your custom code in other classes to access the data. This helps to keep the data access code separated from the presentation code.

Displaying Data With the ObjectDataSource (C#) | Microsoft Docs[^]

If you're using ASP.NET 4.5 or later, you can typically replace the ObjectDataSource control with model binding methods to keep your code even cleaner:

Model Binding and Web Forms in Visual Studio 2013 | Microsoft Docs[^]
ASP.NET 4.5 | Microsoft Docs[^]
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900