DataSource Controls :: Loading Datatable From SQLDataReader Does Not Call Set Method?
Apr 28, 2010
When using the DataTable.Load(SQLDataReader) method, if the datatable is a property of a class, the set method is not called to populate the object. For example...
MySQLDataReader = command.ExecuteReader();
if (MySQLDataReader.HasRows)
myObjDataTable.Load(MySQLDataReader); -- The result of this will be 0 rows returned. The "Set" method of the object is never called.
View 1 Replies
Similar Messages:
Mar 30, 2010
I have several methods where I return a SqlDataReader to populate Gridviews, Listview, etc. I get random "Timeout expired" errors regarding connection pooling, so I decided to add using{} to my methods. The lack of using is a carry over from my more beginner days.Below I included the before and after code. The after code always gives me the "Invalid attempt to call FieldCount when reader is closed" error. I have tried various combination of using{}, but ALL result in the same error.What am I doing wrong? Also, from the code below what is the best way to structure this code to ensure no connection leakage?Before:
[Code]....
After:
[Code]....
View 6 Replies
May 26, 2010
If I have a DataTable (in-memory) read by my C# program from a flat file, and I want to create it as a new table in a SQL Server database... what is the simplest way to do that?
It seems like something like SqlBulkCopy with an option to create a new destination SQL server table would be on my line of thinking, but I dont see a way.
View 6 Replies
Mar 11, 2011
I am trying to load data from an existing DataTable into a new DataTable. Not sure how to get it started. Do not want to merely copy data, I need to load it in row by row.
protected DataTable GalleryByCat()
{
// GLinks is the new DataTable I want to construct and bind to a DataList, Repeater, ListView
[code]...
View 2 Replies
May 7, 2010
I would like to select some columns from a Datatable, I mean, something like Select Name, Surname, ID,
I'm trying to do something like this:
DataTable dtExcel = new DataTable();
DataRow[] buena = dtExcel.Select("NAME");
in order to get only a view or table with one column (NAME).
View 1 Replies
Jan 24, 2010
I'm trying to add new rows to a data table and then use the sqldataadapter update method bu fund some problems. First, I written this code:
[Code]....
Excuse me but the most part of variable are in italian, however I think it is possible to understand how does it work. If I execute this code I obtain this error:
System.InvalidOperationException: Update requires a valid InsertCommand when passed DataRow collection with new rows.
After this I added these lines of code just above the last line:
SqlCommandBuilder cb = new SqlCommandBuilder(adapter);
adapter.InsertCommand = cb.GetInsertCommand;
and I obtained this error:
Cannot convert method group 'GetInsertCommand' to non-delegate type 'System.Data.SqlClient.SqlCommand'. Did you intend to invoke the method?
View 2 Replies
Jun 18, 2010
I have an application which was recently ported from Classic ASP to .NET 3.5. I'm pulling some data from a stored procedure and once retrieved, I'm doing using the Select method on the DataTable in a loop so I don't have to keep going back to the database.It appears that there's something wrong here as I can refresh the page repeatedly and see the memory usage increase by a few megabytes, up to the point where we get an error. If we recycle the app pool in IIS, it starts working again, for a little while.
Is there a memory leak in this method? I did some research on the subject and Microsoft said there was an issue like that in .NET 1.0 and 1.1, but I'm using a higher version.Or, is this something else, such as not managing resources correctly? Here's a snipped of my code:
[Code]....
Initially, this app was using XML instead of a datatable and using XPATH to query the data, but it was too slow. I thought using a dataset with DataTable selects was a better option, but now we found this issue. I was thinking since the loop executes several hundred times that getting all the data and filtering through it on the client was a better choice instead of calling several web methods to get the subsets of data.
View 5 Replies
Feb 19, 2010
it is apparent that "string builder" is better for building large string compared to sMyString = sMyString + "something";
what is a better way to search large in memory datasets? (like the example above - i know i could use loops, is there another way that i dont now about?)
View 5 Replies
Apr 2, 2010
Does dataset store all its datatables' records into server memory if I just call one datatable from it?Lets make an example, a dataset with three datatables - tbCompany, tbCompanyStaffs, tbSalesOrderwhere tbCompany is the parent of tbCompanyStaffs. tbSalesOrder is an independant table.Does dataset load all tbCompanyStaffs records into the server memory as well when a class retrive data from tbCompany?
View 3 Replies
Nov 18, 2010
I want to call a method in the code behind file from the aspx file, but I can't get the TypeName propery correct.
I can call methods in the dll:s in the bin folder and from files in the app folder, but not from code behind in the aspx page. What do I need to do.
View 1 Replies
Aug 19, 2010
I am trying to run a stored proc from this function. When I run it thorugh the debugger I can see that myReader.HasRows = true and myReader.FieldCount =14.
But the control does not go in the loop while (myReader.Read()) where I am trying to read Version field returned by the stored proc.
[Code]....
View 3 Replies
Sep 24, 2010
I'm trying to convert some code from VB to C# on a site i'm working on and can't seem to get the arraylist to function properly.
Here is what we currently have in the codebehind:
[Code]....
Which we then call from the page using:
[Code]....
I want to convert this to C# as the rest of the code on the new site is in C# and I'm having problems with the ArrayList. I've got the other parts of the code all converted fine it's just the GetContent Function that isn't working right. Here's what I have:
[Code]....
I got an error on the "objSDR.Item" part of the code saying "SqlDataReader doesn't have definition for Item" and so if I changed this to the code above. Only problem now is I can't call this from the page using the code below as there is no "Item" in the GetContent Function any more
[Code]....
[Code]....
View 8 Replies
May 2, 2010
In SQL Server 2008 bit is like boolean (true/false), but I tried to read the bit value (0 or 1) and got error. How can I read it?
[Code]....
View 1 Replies
Apr 18, 2010
how to read data from the sqlDataReader .
sqlDataReader sdr = sql_comm.executeDataReader();
if(sdr.hasRows)
{
while(sdr.read)
i=0
[code]...
View 3 Replies
Feb 18, 2010
Why SqlDataReader Class object is not created by "new" Operator.
Is it not possible to create the object like below
SqlDataReader dr=new SqlDataReader();
dr=cmd.ExecuteReader();
Why the constructor of the SqlDataReader class is internal?
View 2 Replies
Jun 17, 2010
[Code]....
My question is how do i use SqlDataReader to read the last row added to a table getting the contents of a column and storing it as a c# varaible
View 2 Replies
Feb 19, 2010
When I am using SqlDataReader class on that time without creating instance of the SqlDataReader Class I m using Command.ExecuteReader() Method. Why We not create the object of the SqlDataReader Class by using " new " Operator.We use like below:
SqlDataReader dr=cmd.ExecuteReader();
Why not we use this class like below:
SqlDataReader dr=new SqlDataReader();
dr=cmd.ExecuteReader();
View 2 Replies
Jan 11, 2010
i have the dataset with one table.Table contains three column like 'Name','Location','Pin'.I would like to move the data from another table based on schema.
View 2 Replies
May 14, 2010
I have two datatables, I want to get all records which are in one datatable but all matching records which exist in another datatable should not be available.
In terms of set, you can say that record which are in 1st datatable but not in 2nd DataTable.
View 13 Replies
Aug 25, 2010
I know it is recommended to use a using statement with a sqldatareader, but I was wondering if it is necessary when you are setting the datasource of a control to a datasource directly. in some places in my code I do this.
using (SqlDataReader reader = getReader())
{
while (reader.Read())
{
// do stuff with data
}
}
when binding to a control I do this.
ddlCustomer.DataSource = getReader(); // get Reader returns a sqldataReader
ddlCustomer.DataBind();
In the second case, do I need to use a using statement. Do i have to first declare an SqlDataReader in a using statement, then set the DataSource to that object. Seems like more clutter in the code, so i was hoping binding to the SqlDataReader disploses of the SqlDataReader.
View 3 Replies
Oct 18, 2010
I have an ObjectDataSource that I want to perform updates using a business entity i.e. Type="Object"). Since the values for the entity are within a user control, I have stored a reference to the control in Session and in the updating event, set the new instance to the value of the entity from the user contol property (which also pulls values from the form viaother properties of the control):
Protected Sub MasterDataSource_Updating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs) Handles MasterDataSource.Updating
Dim entity As New Login()
Dim accountControl As AccountInfo = TryCast(Session("AccountCtrl"), AccountInfo)
entity = accountControl.Entity
e.InputParameters.Add("entity", entity)
End Sub
And here's the markup for the datasource:
<asp:ObjectDataSource ID="MasterDataSource" runat="server" EnableCaching="true" CacheDuration="10"
SelectMethod="SelectAll" UpdateMethod="Update" TypeName="Data.DAL.LoginDAL">
</asp:ObjectDataSource>
My question is, how can I get the update method to pass this entity to the update method in my BLL class? It seems the Update method requires an ID or reference to the original object to use in determining whether any changes have taken place, but I don't really want to do this. In other words, I just want to use the Update event on my ObjectDataSource to pass my entity to the method ("Update") I set as a property and then let this business method handle the update of the data. Shown below, is the BLL update method I want to call:
Public Overloads Function Update(ByVal entity As Login)
If entity Is Nothing Then
Throw New ArgumentNullException("entity")
End If
MyBase.Update("UpdateLogin", entity.Username, entity.Password, entity.FirstName, entity.LastName, entity.Role, entity.Region, _
entity.Email, entity.Title, entity.TierID, entity.Street, entity.City, entity.State, entity.Zip, entity.Mobile, entity.Phone, entity.Fax)
End Function
When I try to call this as it stands now, I get an error: ObjectDataSource 'MasterDataSource' could not find a non-generic method 'Update' that has parameters: ID, entity. Previously, I'd set up a long list of parameters of basic data types (string, int, boolean), but this is rather cumbersome and I was hoping to use an entity for this (FYI, I also got the same type of error when I tried this approach, but with the ID as the
last parameter in the list). Perhaps what I'm doing here is atypical to how the ODS is normally used?? Has anyone done something like this successfully?
View 1 Replies
Mar 4, 2010
I have an ActiveX object which extends some functions. I have a web page that loads the ActiveX object and calls its methods in Javascript. The ActiveX object has two method; the problem is that Javascript can successfully call one of them but fails to call the other; citing Object doesn't support this property or method which is nonsense because I made a VB6.0 application that successfully calls this other method, so the two functions are indeed extended correctly and performing their job. And yes, the Internet Explorer security zones are all set and everything, as I wrote above the javascript code can call one method but refuses to call the other.
View 1 Replies
Sep 4, 2012
i have 2 dropdown list and i need to create a Generic method so that I an reuse it...
View 1 Replies
Sep 14, 2010
I want to execute a certain piece of code by default before each web Method.
Without adding any extra code in each method how to achieve this?
I am calling this service from Win application.
View 1 Replies
May 7, 2015
how to execute a method in C# when web form is fully loaded ? i am not talking about Page Load , after everything gets loaded i want to run a method
View 1 Replies