VS 2010 - Return Data Reader Or Dataset / Datatable
Dec 18, 2010
Had a datareader question.
Return myDataReader I have a function which is retuning a datareader to various sections of my website which is then being bound to dropdown lists, gridviews, etc. Normally the last line in a function when is the data reader and connection getting closed? Is it best practive to return a data reader or a dataset/datatable (or something even better than these two)?
I'm making the leap from using all the 'wizards' that are built into VS, and have been doing more with code-behinds. But, I'm curious as to when/why I should use a reader, versus a databable, table adaptor to "manage" the data returned from a stored procedure. Typically, the data is to be displayed on a webpage, and not written back to the database. What's the difference? When should I use one over another?
I want to take my return value from sql server to c#.
ALTER procedure [dbo].[userss](@email varchar(100),@password varchar(25),@name varchar(250),@DOB varchar(20),@acc_vari int,@ip_address varchar(50),@vari_code varchar(7) ) as begin declare @uid int select @uid=uid from users where email='12we' if(@uid>0) return 0 else insert into users values(@email,@password,@name,@DOB,@acc_vari,@ip_address,@vari_code ) end
In this i want to take return value "return 0 " from sql server to c#.
In a VB.Net project I use the Adobe PDF Reader (AxAcriPDFLib) control to display a preview of a selected PDF document whereafter the user can double-click upon the selected listbox item to enjoy a full screen view of the relevant PDF document. see the attached sample in this regard. Is there any way to emulate this in ASP.Net?
I need your help / guidence for doing custom paging in c#, through sqlserver. so that i can have data in dataset/datatable according to the pagesize given, not all the data in dataset. some code /url .......with full discrption if possible.
I am trying to return a dataset. I must be doing something wrong. The returned dataset in this sample code indicates there is a datatable, Users, but there are no datarows. What am I doing wrong? This example is only using the rows.count, but of course I really need to use the whole datatable as the datasource for a gridview.
Public Function getmyds() As DataSet Dim dsUser1 As DataSet = New DataSet() Dim tbUser1 As DataTable = dsUser1.Tables.Add("Users") tbUser1.Columns.Add("UserName") tbUser1.Columns.Add("Days Remaining") tbUser1.Columns.Add("UserAccountControl") Dim rwDefaultUser1 As DataRow = tbUser1.NewRow() rwDefaultUser1("UserName") = "John Smith" rwDefaultUser1("Days remaining") = 100 rwDefaultUser1("userAccountControl") = "Enabled" Return dsUser1 End Function
I'm using a table adapter to perform my queries. I'm sure I'm missing something really easy, but I can't figure out how to return the number of rows returned from a query to a dataset used for a GridView.Basically, I want to display a message "No records exist for your selection" by testing for ReturnedRows = 0.
Excerpt of C# code:
handoutDSTableAdapters.handoutTableAdapter handoutsAdapter = new handoutDSTableAdapters.handoutTableAdapter(); gv_Handout.DataSource = handoutsAdapter.GetDataByDoctor(Int32.Parse(ddl_MD.SelectedValue)); gv_Handout.DataBind();
I have gone through this article at microsoft web site, which deals about calling the custom code in Reporting Services.But I need to know whether it is possible to process the data (call a dll function) and return a DataSet as the input to the report instead of directly binding the dataset. I have gone through many links which deals with custom code that returns the scalar value(such as Boolean, String, Decimal, etc).As I'm using Delivery & Subscription concept, I need the business logic to be called and return the DataSet to be the source for generating report. Please clarify me on this.
I have a Gridview and two link button in that GridView , one link button click is to add edit row ( Edit ), one link button click is to select row ( Select ). I have a dropdownlist inside row which selected when i click link button Select in the gridview edit template, as of my business logic i need to show the dropdownlist only when the user clicks Edit button and when the user clicks Select button . That mean when the user clicks Select button then they clicks Edit button on the gridvview i should allow him to edit the dropdownlist (showing the value to the user through a label).
When I click Select link button , then I click Edit link button . They have errors : Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index" I don't know what error?. How to fix it
I'm trying to import a dataset/datatable into a SQL Server table that will have changes I have a program that creates two datasets. One dataset comes from SQL Server (original data) and the other is being imported from Excel (altered data). The user will have made changes to certain cell values within the excel dataset from is on file with the SQL Server table. What I would like to do then is to update SQL Server table with the contents of the dataset/datatable that came from Excel. I know that SQLBulkCopy can do an insert into a temporary table. However, I have 14 tables that I would have to create and also keep track of column changes if the original SQL Server table were to change. Can this be done with doing an update back to the original SQL Server table?
I have some code in my vb.net code behind that queries a database, and if there is data, outputs it from the codebehind to a datalist on my asp.net page. In addition to sending the data to the datalist on the page, I need to take the value from "mbillaty" that is returned from the sql query, and have that value be the selected value for a drop down box also on the page. I can get either the datalist to fill, or the selected value for the dropdown box to be selected depending upon which bit of code I place before the other (ARGH), but I can't get them to both work together on the page. What am I doing wrong?
If I need to fetch one whole column from Table1 in the DB, should I fetch it using datatable or dataset? I can do both ways. I mean ok I should use Datatable. Why is that? What would happen if I use Dataset? ok that's what I wanted to know. So there's memory issue. I mean whatever I use be it Datatable or Dataset, both will be fetching only ONE column frommy table in DB. How is Dateset's gonna use more memory then?
Is it possible to add/set the dataset back to a dataTable. The dataset is already populated with the resultant data retrived from three different tables. The reason for this is to be able to loop through the table and create a template column in the table dynamically. I am writing the code in C#.net.
I have created alot of stored procedures in my application that return the result of a query in a datatable object. I never use a dataset. Why would I ever use a dataset over simply returning the result of a query as a datatable object?
i have one question for my project. i am fetching all users data in one dataset, but each user will be in unique datatable to avoid no. of database connection i will fetch data in one single transaction no. of user are more than 10000 ..is it practical to store more than 10000 tables in one single dataset what will be then performance issue for the same, it will be the diffrent application for my project to generate this much of data. how many no. of table one dataset can contain in visual studio 2008 with 3.5 framework?
I have 2 DataTables and 3 DataGrids. First one shows data from first dataset, and second one from second dataset. And the third one shows relational data from those 2 tables. Here is some sample code (
Private Sub Page_Load ......... Dim dss As New DataSet dss.DataSetName = "dset1" Dim dt1As New DataTable dt1.TableName = "tablo1" dt1= c2data.En_Cok_Satilan_Getir 'function returns datatable from DAL Dim dt2As New DataTable dt2.TableName = "tablo2" dt2= c2data.En_Cok_Alinan_Getir 'function returns datatable from DAL dss.Tables.Add(dt1) dss.Tables.Add(dt2) dss.Relations.Add("baglanti", dss.Tables("tablo2").Columns("stok_kodu"), dss.Tables("tablo1").Columns("stok_kodu")) ' other codes goes here End Sub
When I load the page for the first time, everything works fine, all 3 DataGrids shows proper results. But when I refresh the page by hitting "refresh" button or by hitting F5, I am getting "DataTable already belongs to another DataSet" error message for "dss.Tables.Add(dt1)" line. I can solve this problem by using copy of that table ("dss.Tables.Add(dt1.Copy)". And then "dss.Tables.Add(dt2)" gives me same error message. Again, I can solve this with same method "dss.Tables.Add(dt2.Copy)".
What I would like to know is, which dataset owns my datatables and why doesnt it released and retains for the second request? Refreshing page re-creates new datatables and new dataset, doesnt it?
I am trying to make a user control which has a gridview bound to a sql datasource.On the gridview user control, a user would select some fruits and press insert button and the user control would return a datatable/dataset of the selected items which then get databound to a gridview on the parent page. 1) I have made the user control with the gridview and buttons Included it on form and its working fine3) How to return a datatable from my user control and bind it with the parent page gridview?
Dim cmd As New SqlCommand cmd.Connection = New SqlConnection(<connectionString here>) cmd.Connection.Open() cmd.CommandText = "Select * From table_name" Dim da As New SqlDataAdapter(cmd.CommandText, cmd.Connection) Dim ds As New DataSet da.Fill(ds) ' I want to do some query with THIS dataset cmd.Connection.Close()
I want to do a query based on the dataset ds. Let's say I want to filter out names that starts with "a". If yes, how do you do it?
I am trying to eliminate multiple calls to a SQL database from the same page. I create a dataset and data table, but it is only available to the function that creates it. How can I continue to use it with other functions in the code behind on the same page? Is there a way to make it public like a variable? I don't want to display a datagrid on the page.
I can fill and then return typed dataset from a web method, but applying these steps by using Typed Datatable instead of Typed Dataset I cannot return filled typed dataTable. So, is it possible to return typed dataTable from a web method? If yes, how can I do this?
I shall give a little bit information about my project. There is 3 project in my solution. I) Presentation Layer (WinForm), II) Business Layer (Web Service) , III) Data Access Layer (Win form project type)... The problem is that;
I use 2 seperate methods. 1st is FillTable() which fill a datatable in my Typed Dataset in Data Access layer. The 2nd isGetTable() which should return typed datatable filled by FillTable() method. I try these methods and FillTable() methods (goes from I. layer to II. Layer and then III. layer) fills a datatable properly and after that I can return this datatable by calling GetTable() method from Typed Dataset (in III. layer) to WebService. I have tested the rows count of returning datatable and there is no problem up to WebService. But even after returning this typed datatable from WebService the table comes to Presentation Layer empty. So, there is a problem returning filled typed datatable from WebService to WebForm (from II. layer to I. layer).
On the other hand, if I try this methods by returning Typed Dataset instead of Typed Datatable, I can return properly with a filled datatable in Typed Dataset. But, I relly do not want to return a huge filled dataset which may contain 15 tables instead of one datatable. My questions;
1) Is there any logical approach mistake on my Layer Architecture?
2) What should I do in order to get a Typed Datatable from Web Service (II. Layer of my project)?
I am trying to pull data from a table apdater i have in a XSD file, the xsd file pulls information from a sql express db file. i have been taught thats a good way for n tier archecture and the lecture insists its done this way, I am trying to learn C# as I feel I have learnt enough VB and would prefer to go the C# route.
Here is the VB code I wrote:
' Create the table adapter Dim ta As New DataSet1TableAdapters.CustomersTableAdapter ' Create a Datatable Dim dt As New Data.DataTable Pull the data from the table adapter into the Datatable
I have 2 views in sql server and I create a dataset with those 2 views as datatables. Now I need to create a datatable and programmatically fill it with the other 2 datatables. Take the 2 datatable and create a third one in the dataset not create a third view in sql server.