.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


Similar Messages:

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

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

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

DataSource Controls :: Pass In As An Insert Parameter For SQLds2 The Scope_identity Of The Insert Of SQLds1

Jan 12, 2010

I am trying to pass in as an insert parameter for SQLds2 the scope_identity of the insert of SQLds1.

Exception Details: System.InvalidOperationException: Error executing 'InsertCommand' in SqlDataSource 'SqlDataSource1'. Ensure the command accepts the following parameters: @Name1, @NewId

[Code]....

View 4 Replies

ADO.NET :: Linq To SQL Insert To Datatable?

Sep 20, 2010

I got the following query to group the table. I am wondering how to add a subtotal record with anonymous type.

string prevOriginator = string.Empty;
var oOriginator = (from I in dtIssue.AsEnumerable()
group I by new {RaisedBy = I.Field<string>("RaisedBy"), ItemType = I.Field<string>("ItemType")} into grp

[code]...

View 1 Replies

Insert ADO.Net DataTable Into A SQL Table?

Mar 18, 2010

The current solution i implemented is awful!

I use a for... loop for inserting records from an ADO.NET data-table into an SQL table.

I would like to insert at once the data-table into the SQL table, without iterating...

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

ADO.NET :: Insert Customized Bulk Data Into Sql Datatable?

Jul 29, 2010

What I am trying to achieve here is, I am supplying xml as string (varchar) to my stored procedure, In stored procedure I want to parse this xml and fetch each Promotion record and insert into my table. Also once each record is inserted, I need to fetch the Identity of that record alongwith the AreaID attribute from the Parent node "Promotion" of each Promotion record and insert into second association table. how would I go about doing it, my generated xml is given as under.

[Code]....

View 2 Replies

ADO.NET :: Use Transcation When Insert From Datatable To MSSQL Server?

Jan 20, 2011

i have to insert values in two tables on save button click.ne sipmle insert and return a order_id.that id is used for inserting order details information.i am using a datatable to store this information,then insert to table.i want use Transaction for both insert on save button click.

View 1 Replies

Access :: Master/Details Datatable Insert

May 29, 2010

I have a text file coming from another system that is in fixed format with header and details information regarding a request of material, looks like:

HDR 1000 HeaderDescription
DTL ProductId Productdescription qty ...........
DTL ProductId Productdescription qty ...........
DTL ProductId Productdescription qty ...........

I can read the file using streamreader on a "continous way" inside a do while loop, and parse it to obtain th different fileds required.i want to read the file, identify header line and fill a datatable, then identify details lines and fill another datatable to be able to insert both tables on the same transaction scope, if something fails rollback the insert.Im using a access 2003 database as backend and custom DAL and Business objects.

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

Dynamically Insert Rows In An Existing DataTable (No DataSource Used)?

Jun 1, 2010

I have created a datatable with three fields namely TimeTask, TaskItem and Count (count of user) eg; {"12:30AM-01:00AM" , T1 , 3}.

dataTable.Columns.Add("Task Time", typeof(string));
dataTable.Columns.Add("Task", typeof(string));
dataTable.Columns.Add("Count", typeof(int));
dataTable.Rows.Add("12:00AM-12:15AM", "T1", 6);
dataTable.Rows.Add("12:45AM-01:00AM", "T1", 5);
dataTable.Rows.Add("01:00AM-01:15AM", "T1", 1);
dataTable.Rows.Add("01:15AM-01:30AM", "T2", 4);
dataTable.Rows.Add("01:30AM-01:45AM", "T2", 9);
GridView1.DataSource = dataTable;
GridView1.DataBind();

In this there is no task for the TimeTask "12:15AM-12:30AM" and "12:30AM-12:45AM" yet the TimeTask should be inserted as,

TimeTask TaskItem Count
12:00AM-12:15AM T1 6
12:15AM-12:30AM - -
12:30AM-12:45AM - -
12:45AM-01:00AM T1 5
01:00AM-01:15AM T1 1
01:15AM-01:30AM T2 4
01:30AM-01:45AM T2 9

How to chk for the missing rows? Is it possible to dynamically insert rows in an existing DataTable (No DataSource used) in this scenario.

View 1 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

DataSource Controls :: Update Only Changed Or Insert New Rows In Datatable?

Mar 4, 2010

Existing records can be updatedNew records can be insertedAll existing records can be deleted & new ones can be insertedExisting records have a primary key field
New ones are just blank inserts

All this detail is stored in a data table. On form update I only want to update existing (only modified rows) & insert new rows. I have gone about loading the changed records in a new data table

DataTable changedRecordsTable = dataTable_old.GetChanges();

How do I compare it with all the records in the old datatable and pass them to the save query ?

View 2 Replies







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