ADO.NET :: How To Pass The DataTable From One Method To Another In The Same Class

Aug 17, 2010

I am learning Asp.net web application. I have one doubt.

Is it possible to pass the DataTable from one Method to another in the same class?

View 4 Replies


Similar Messages:

DataSource Controls :: ObjectDataSource - Update Method To Pass Entity To The Method In BLL Class?

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

.net - Insert Value In Datatable And Pass It Into A Method?

Sep 22, 2010

i just use this code to insert value in datatable and pass this table in method
look code---

public class RoomBO
{
DataTable dt;
RoomDal objRoom = new RoomDal();
public int insert(int room,string bedType, int bed, int charge)
{
//adds the details of the new room
dt = new DataTable();
dt.Columns.Add(new DataColumn("Column1"));
dt.Columns.Add(new DataColumn("Column2"));
dt.Columns.Add(new DataColumn("Column3"));
dt.Columns.Add(new DataColumn("Column4"));
DataRow dr;
dr = dt.NewRow();
dr["Column1"] = room;
dr["Column2"] = bedType;
dr["Column3"] = bed;
dr["Column4"] = charge;
objRoom.Save(dt);
return 1;
}

*on data access layer*

public int Save(DataTable dataTable) //adds the details of the new room
{
ada = new SqlDataAdapter("room_insert", con);
//DataRow r= dataTable.NewRow();
ada.SelectCommand.CommandType = CommandType.StoredProcedure;
ada.SelectCommand.Parameters.AddWithValue("@room_no",
Convert.ToInt32(dataTable.Rows[0][0]));
ada.SelectCommand.Parameters.AddWithValue("@room_type",
Convert.ToString(dataTable.Rows[0][1].ToString()));
ada.SelectCommand.Parameters.AddWithValue("@no_bed",
Convert.ToInt32(dataTable.Rows[0][2]));
ada.SelectCommand.Parameters.AddWithValue("@charge",
Convert.ToInt32(dataTable.Rows[0][3]));
ds = new DataSet();
ada.Fill(ds);
return -1;
}

i am not getting any error but value is not insert to my database

View 2 Replies

Pass Datatable To The Mvc View Error / CS0246: The Type Or Namespace Name 'DataTable' Could Not Be Found

Sep 28, 2010

I was reading: [URL]

But I have give a compilation error:

CS0246: The type or namespace name 'DataTable' could not be found (are you missing a using directive or an assembly reference?

View 1 Replies

C# - How To Execute Base Class's Method Before Implementors's Method

May 12, 2010

I have the following page

[Code]....

Currently, only GenericOfflineCommentary's ExtractPageData() is firing. How can I modify this to first run OfflineFactsheetBase's ExtractPageData() and then GenericOfflineCommentary's?

edit: I'm trying to avoid having to call base.ExtractPageData() in every implementor.

View 2 Replies

C# - How To Call Class & Method From A Button In Another Class

Jun 24, 2010

I have a WindowsForm that has a DataGridView that shows output of my app. The class with the button is DriveRecursion_Results.cs. I want it so that once the button is pushed by the user, my method FileCleanUp() in my SanitizeFileNames class is called. I'm not quite sure how to do this though.Here is the code for both classes:

public partial class DriveRecursion_Results : Form
public DriveRecursion_Results()
InitializeComponent();
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
[code]...

View 1 Replies

C# - How To Pass A Class Into Another Class To A Codebehind

Aug 3, 2010

How to pass a class into another class to a codebehind?

When I debug and check the myCategoryObj in the Default.aspx page, I can see the object is in the debug. What am I doing wrong?

I know I could create the object in the Default.aspx but I should not have to I should be able to call the Business Logic Layer and ask for an object back and then fill the object and pass it back to the Business Logic Layer to be saved (insert or update).

[Code]....

View 1 Replies

How To Force Web Service Base Class Method Run Before Web Service Method Start

Aug 6, 2010

My web services have base web service method called IsGood()I want to make sure every methods in my web service call IsGood() in base web service automatically without add code in each web service method, can I do that?

View 2 Replies

ADO.NET :: Correct Way To Fill A DataTable With A TableAdapter Method?

Dec 1, 2010

I have a dataset with a table adapter that has several queries. I want to execute on of the queries and fill a data table but am having trouble with this operation. Am I invoking my table adapter incorrectly? See line 56.

[Code]....

View 2 Replies

Add Records From DataTable To ArrayList Using AddRange Method?

Mar 25, 2011

i have a dataTable, which contains a column which has 100 rows, now i want to add those rows in ArrayList, but not with the Add Method, because i have to use for loop for adding records one by one, so i want to prefer addrange method of arraylist, so it is possible to add records in arraylist from DataTable using AddRange.

Below is the code which i am using.

Dim adapGetImages As New SqlDataAdapter("select distinct FileName from Files where Filename<>'' and (RIGHT(FileName,3) = 'gif' or RIGHT(FileName,3) = 'jpg' or RIGHT(FileName,3) = 'bmp') order by FileName", connection)
Dim dtGetImages As New DataTable()
adapGetImages.Fill(dtGetImages)
ArrayList1.AddRange(dtGetImages.Rows[0][0].ToString())

The last line is where i am stuck. as if i run this it will just add single row, and if i say dtGetImages.Rows.ToString() then this will just Add System.DataRow in Arraylist and not its content.

View 2 Replies

Forms Data Controls :: Pass Datatable Value To Gridview Pageindexchanging Event?

Apr 14, 2010

i am trying to set paging using the following code in pageload event.

GridView1.DataSource = ourdataset.Tables("Products")
GridView1.DataBind()

when i select the page button the parameter value ourdataset.Tables("Products") is set to nothing ?

Protected
Sub GridView1_PageIndexChanging1(ByVal sender
As
Object,
ByVal e
As System.Web.UI.WebControls.GridViewPageEventArgs)
Handles
GridView1.PageIndexChanging
GridView1.DataSource = SortDataTable(ourdataset.Tables("Products"),
True)

View 6 Replies

Data Controls :: Pass DataTable Or Dataset As Parameter To WebMethod Of WebService

Mar 16, 2014

can datatable pass to web service as input parameter? i have a scenario to pass values as datatable to web service. eg as follows

when Invoice or Bill is entered, I want to send the entered data as datatable to web service to insert into another application.

View 1 Replies

DataSource Controls :: Selecting Columns From A Datatable Using Select Method?

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

DataSource Controls :: How To Add Rows To Datatable And Use Sqldataadapter Update Method

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

DataSource Controls :: Possible Memory Leak In DataTable.Select Method?

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

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

Web Forms :: How To Bind Dataset Or Datatable From Web Method To Datalist Using JQuery

Jun 25, 2012

[URL]

     like above link i want to bind 

     name.....................

     city...... country.........  

for suppose 10 employee. for that i try to bind datalist using webservice & jquery. but i get lots of problem to bind datalist. with name as hyperlink so that when i click at name it go to next page and show details. 

View 1 Replies

ADO.NET :: Class 'system.data.datatable' Cannot Be Indexed Because It Has No Default Property

Dec 17, 2010

I'm trying to get a custommembership to work and i have the following problem.

i get a error class 'system.data.datatable' cannot be indexed because it has no default propert.

Here's my function.

Public Overrides Function GetUserNameByEmail(ByVal userEmail As String) _
As String
Dim userName As String = ""
Try
Dim mymember As New Data.DataTable

[code].....

View 4 Replies

Web Forms :: Foreach - Datatable / Extend Or Create A Class For This Functionality?

Feb 18, 2011

I cannot use foreach with datable.

In that case if i wish to extend or create a class for this functionality

how do i proceed?

View 5 Replies

C# - How To Pass In A Method Name As A Parameter

Dec 10, 2010

I've just noticed I'm repeating a lot of C# code in my ASP.NET application so want to create a generic method. I have a series of private methods like this:

[Code]....

So, I want to replace DB.MyRepeatedCall, chtMyRepeatedChart and pass them in as parameters to a generic function. Is that possible? I have many charts on my form that take the same number of parameters.

UPDATE

Following Frederik's solution I have done this:

[Code]....

I am calling the function with this command:

PopulateControl (chtEquityCurve, DB.GetAccountBalances());

I get this error in the intellisense:

No overload for method 'GetAccountBalances' takes 0 arguments.

View 4 Replies

DataSource Controls :: Recommended Searching Method For In Memory Dataset (datatable)?

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

C# - How To Create A Extension Method To Sum Up A Column Of A Generic Constrained Type In A Datatable

Oct 1, 2010

Is something like the below possible?

public static T Sum<T>(this DataTable dt, string columnName)
where T : IEnumerable<decimal>, IComparable<decimal>[code]....

It feels like i'm almost there, but not quite :/

Just trying to sum up either decimal or int values in a column in datatable. Currently getting a compile error, however think this is due to the incorrect generic constraint.

View 3 Replies

Data Controls :: Generic Method To Bind DropDownList With DataTable Or DataSet

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

C# - Can Pass Dataset To A Web Service Method

Feb 11, 2011

can we pass dataset to a web service method? If yes , then how?

View 3 Replies

MVC :: Pass Parameter To ActionResult Method?

Mar 17, 2011

I have an ActionResult Method defined as following;

[Code]....

I am using JQuery and would like to know how I call this method passing a parameter. I have the following which does not work;

[Code]....

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved