Which is better for binding data to the Grid & for data access.

I have 2 sample codes I want to share, I just want to know which is better.

1.

Class Module:

Public connClaims = <connection string>

Public Function ExecQuery(ByVal ConnStr As String, ByVal query As String, ByVal tablename As String) As DataTable

Return ExecCommand(ConnStr, query, tablename)

End Function

Page:

Dim dtAgent As New DataTable

dtAgent = objLibMain.ExecQuery(class1.connClaims, "Select * from ...", dtAgent.TableName)

GridView1.DataSource = dtAgent

GridView1.DataBind()

2.

I'll Just use a sqldatasource?

like for example:

Sqldatasource1.selectcommand = "Select * from........."


ez
0
Ez416
5/5/2009 1:12:13 AM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

3 Replies
1508 Views

Similar Articles

[PageSpeed] 58

Hi,

Wizard DataSource such as SqlDataSource are good but for me,I would prefer using (Option 1 with DataSets/DataReader over Wizard DataSources)- I called it the hard-coded dataset  because I can write my own logic there. SqlDataSource is good and could be preferred if a simple query is to be generated. But it tends to get complicated and confusing when it comes to intertwined queries. SqlDataSource is also hard to maintain in case of huge blocks of code and we have to generate umpteen DataSources for different data controls. Where as in the case of hard-coded sql databind, we can reuse the code without any hiccups changing the basic query here and there according to requirements and It is also a lot easier to maintain it.

We also discussed the related topics here

http://forums.asp.net/p/1276704/2428580.aspx#2428580

http://forums.asp.net/t/1217976.aspx

 


Regards,Vinz

"Code, Beer and Music" that's my way of being a programmer!

How to get your Forum Question Answered | Blog | CodeASP.NET
0
vinz
5/5/2009 2:49:54 AM

 Hi Friend,

     You can bind the grid manually or with sql datasource. As  a programmer we must know what will happen in the code and what time the code will be execute. If you are using sql datasource we need to declare every thing before page execution. If we need to assign at the runtime somany complications will come with the sql datasource. So manually binding the data to the grid is better. If we are not using multiple tables then datatable is better than the dataset.

 



 


Thanks,
R.charan kumar

Please mark the most helpful reply/replies as "Answer".
0
charan2021
5/5/2009 3:18:58 AM

You mean to say if i am not going to use 3 or more tables, it is better to use data table?

& if I use 3 or more table is it better to use dataset?  dataset are use by sqldatasource, am I right?


ez
0
Ez416
5/5/2009 3:54:32 AM
Reply:

Similar Artilces:

Bind Data to an Image Control not in a Data Presentation Control
I've been searching for two days but I don't really know what to search for.I'm making a site for a photographer.  The Default.aspx page displays Albums by showing a title, image and description from the database table Albums. Click an album to view the contents and it passes the QueryString which is AlbumName.  The ViewAlbum.aspx page uses the QueryString to display an UpdatePanel holding a Large Image and a Repeater full of dynamically filled ImageButtons for thumbs.  Both are from the database table Photos and are retrieved using an ObjectDataSource. Click the ...

Data presentation control in another Data presentation control
 Hello,I want to make a menu with datalist or gridview control.Basically,the menu will be like this,Categories     Sub Categories.For example, for COMPUTING category there will be NOTEBOOKS DESKTOPS etc.There will be a image for CATEGORIES and linkbuttons with Subcategories.If I put a datalist inside a datalist and a link button inside the second datalist visually it satisfies my need.However,CommandArguments come from database to linkbutton.Andwhen one of these command buttons is cliked it must go to proper page.I dont know how to wrie an event_handler ,specifically, for...

data, data, data
Hello, I need some advice on the best method to keep a database updated in this scenario. I have a local Solomon SQL Server where we keep our inventory. I want to build an application that will be hosted at a remote hosting location which provides a SQL database. I want to build the application to allow clients to access the inventory items and make requests based on the remote SQL data. The order will be sent to our fulfillment department via email; they will fiill the request and ship.  I'm not sure the method to do this while keeping the data current on the remote and the l...

binding data when no data present
hello all i am displaying the payment details of a client in a repeater control. now if the payment exists for the customer then there is no problem but if it doesnt exist then i would like to display somthing like no payments made or n/a. but i dont how i do this thanks in advance Vignesh Hi Vignesh! I would suggest you check your datasource. If it contains any "rows", you bind it, and if it doesnt, you display something else. If you want an example, let me know what kind of object you're binding, and I'll provide you with one :-) hi David Thanks for replying. i am binding som...

Diff Between Data Reader & Data Set in Webb App / Grid COntrol
I know this subject is probably a little to big for a forum answer but I have been wondering what the difference is between a datareader and a dataset is in terms of a web app? Whether I use a datareader or a dataset to populate a grid with 100 records, the html sent to the browser is almost exactly the same, judging from the browser's source button. I would also think that once the grid is populated by the dataset or datareader object and control exits the function, both the data reader and the data set object would be destroyed, only to be recreated the next time the grid is p...

Data Connection has no data in the data grid???
I have a data connection that I use to create a data set and I bind the data set to a data grid, but when I run the page no data or grid appears... I know there is data in the table that the data connection attaches to. Please review my code below and offer suggestions why my data grid is empty. Thanks,Ryan<%@ Page Language="C#" %><%@ Register TagPrefix="wmx" Namespace="Microsoft.Matrix.Framework.Web.UI" Assembly="Microsoft.Matrix.Framework, Version=0.6.0.0, Culture=neutral, PublicKeyToken=6f763c9966660626" %><%@ import Namespace="System.Data" %><%@ import Namespace...

Data manipulation in data repeater or data grid control problem! Please Help!
Hi all,the following is the structure of my database tabletable {  DateTime StartDate;  DateTime EndDate;  VarChar Event;}I'm trying to grab start date and end date from database, then reformat the Dates to represent as "StartDate-EndDate" and i am using a data repeater control to display the data. How would I do it without adding another column say DisplayDates in the database? I guess my questions is how can I grab values from database, then do some manipulation of that data and display it in a data repeater or data grid control?thanks in advanced! H...

Data presentation without a data control
The Gridview and Formview controls provide good functionality in some circumstances but are clumsey in others. As a newbie to .NET I was wondering if its appropriate to do databinding with textboxes and other data controls outside of one of the new data controls (formview, gridview, etc). Or is it a new standard to always use one of the new data controls. If the answer is yes, would you still use an SQLDatasource, or would you set up the connection in code? And, how would you deal with the syntax? In the Formview we have: <asp:TextBox ID="fnameTextBox" runat="server" ...

clear the data in the data grid control
hi all, I have added records thru the footer column of the data grid. i write the code in the click event of the 'add' button control.my code is inserting the data in to the database and refresh the datagrid with new data.Record is inserted succuessfuly.but the datagrid is updated with old records.(ie) it s repeating the columns again.if i check the ispostback property it will not update the new records.i tried DataGrid1.Columns.Clear(); but it clears all columns. Plz help me it s very urgent to me regards, gowri   regards,gowripillaimark as answer if the reply help yo...

2nd Data Grid Control
Hi, i have a DataGrid control on page that has a hyperlinked field.  When you click on the hyperlink the page opens, and returns the selected information from the database as it is supposed to.  However, I wanted to put another dataGrid on the hyperlinked page that pulls up more information about the hyperlinked item.  I tried this SQL statement but it returns all the rows of the database, when in actuality all i want it the second dataGrid to show certain columns from a different DB table.   SELECT     tbllog.IttNumber, tbllog.IttLog, tbllog.Lo...

need help with autopopulating a data grid from a control parameter of another data grid
I have a datagrid that binds based on what the user selects from a different data grid.  I would like to populate it in the page load based on the first index of the first data grid, or in other words i want the first record automatically selected and the second datagrid to have data before the user selects a record.  thanks for any help. Hi, jwkeenan: You can set the this.SqlDataSource1.SelectParameters[1].DefaultValue = dataGrid1.Items[0].Cells[0].ToString(); in the page load event.Best Regards,__________________________________________________Sincerely,Rex LinMicrosoft Onlin...

Huge data set not binding to data grid
I have a huge query that brings back 30K + records some times the user wants to be able to send this to excel (i know to do that) but the data grid just keeps timing out any ideas on how to present a report of this size to a user they want to sort filter..... Have you tried to set the timeout attribute for the connection to a larger value?Welcome to my SQL/ASPNET forum for Chinese http://51up.org/bbs/forumdisplay.php?fid=38 yes i got it to work but it is taking 5-10 min to bind that much data....

Javasript error when bind data to data grid
Hi all, When i bind data to gird, javascript occurs : Object required.My code very simple:Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim dt As DataTabledt = New DataTable dt.Columns.Add("test")Dim dr As DataRow dr = dt.NewRow dr(0) = "test" dt.Rows.Add(dr) GridView1.DataSource = dt GridView1.DataBind() End Sub   Hope you will help ! thank you very much What else is on your page?  Jason ConwayMCP, MCTS, Certified SCRUM Masterasp.net blog Hi, I have tested your above code and it works...

Data Access Layer & Data Layer
what is the difference between Data Access Layer & Data Layer?? Hi,A data layer is where your DB is (or maybe text files). Like your SQL Server DB is your data layer.Data access layer is the code you write to access the data layer and perform operations.HTH,VivekSocial Networking Platform in ASP.NET || Join now: CodeASP.NET Community Please mark the most helpful reply/replies as "Answer"....

Web resources about - Which is better for binding data to the Grid & for data access. - asp.net.presentation-controls

Binding selectivity - Wikipedia, the free encyclopedia
The concept of selectivity is used to quantify the extent to which a given substrate, A, binds two different ligands, B and C. The simplest case ...

Facebook To Hold Non-Binding Shareholder Advisory Votes On Executives’ Compensation Every Three Years ...
... filing with the Securities and Exchange Commission Wednesday that, as voted on at its annual meeting in June, the company will hold non-binding ...

Molecule World DNA Binding Lab
Get Molecule World DNA Binding Lab on the App Store. See screenshots and ratings, and read customer reviews.

Whitehurst Printing and Binding Co. - Flickr - Photo Sharing!
Photo of Whitehurst Printing and Binding Co. ghost sign in Troy, N.Y. Shot with Agfa Chief camera, GAF Aerographic film (expiration 1976). Photo ...

Binding of Isaac - Top Tips For Survival - DoTheGames - YouTube
Subscribe: http://bit.ly/XAyM4G Twitter: http://bit.ly/T3CQTI Basically a handful of tips that weren't on any Wikis or available without trawling ...

Bill Shorten, Anthony Albanese reject call for binding vote on same-sex marriage
Union leader Paul Howes' call for the ALP to move to a binding vote in support of same-sex marriage has been rejected by Labor's potential leaders. ...

NSW seeks binding bids in Delta Coastal sale
Participants view AGL’s progress in the MacGen deal as a good omen for regulatory consent.

Abigail claims victory with a hushed, spell-binding display
As Abigail Carungay stepped up to the microphone in the final rounds of the Premier's Spelling Bee, the audience leaned forward in their chairs ...

European Union parliament backs plan to relocate 160,000 asylum seekers, approves binding quotas
The European Parliament votes in favour of relocating 160,000 asylum seekers with binding quotas for EU states.

Syria says ready to join 'non-binding' UN peace talks
Syrian Foreign Minister says country will take part in preliminary talks as Russia launches fresh attacks against ISIL.

Resources last updated: 11/24/2015 7:14:12 PM