DataSource Controls :: Adding Rows And Updating Tables From Datatable

Mar 7, 2010

Maybe this could be a simple questino, but for me it's difficult to do this action: I have a table in sql server 2005 with some records stored, for example 10 records. The primary key of this table, let's call it "Employee", it's a number field with an autoincrement constraint. I want to store more data into the table by using a OdbcDataTable object and OdbcDataAdapter and adding new rows to the datatable and afeter that use the "Update" method from the OdbcDataAdapter object.

The big deal is this: let's suppose that I want a add a new record to the datatable object, using any method or code sequence that you want. if I have 10 records stored on the data base table, when I retrieve this table schema by using the OdbcDataAdapter "Fill" method, I have a copy of the data base table schema in the DataTable object, right?. if I add a new row on the datatable object, it's suppose that the primary key column of that table must AUTO-INCREMENT the value of the key, I mean if the last value that I store on the table was the number 10 on the PK field, when I add a new row on the datatable object, the PK value on the datatable object must be the number 11 if the autoincrement constraint is present into the DataTable object, but in my case, it doesn't work

So, How can I define the conditions or set the c# data objects properties to wor in that way???. In this moment the PK column on the odbcDataTable doesn't auto-increment its value when I add a new row on it.

Please helpe with this.

PD: I have another question about the DataTable object, how many records can store this object?? I have some problems with this because sometimes when I use the Fill() method to get data into the DataTable or a DataSet object there's no problem if the Fill() method retrieves about 142000 records, but when I retrieve over the 145000 records, when I inspect the DataSet or DataTable object by using the debuging mode, they have null value. Any of you can tell me why this situation ocurrs??

View 1 Replies


Similar Messages:

DataSource Controls :: How To Select Rows From A DataTable And Create A New ViewList With The Selected Rows Only, While ...

May 31, 2010

I have one big DataTable with X rows. I want to select Y rows from it and bind them to a new ViewList. While doing it, I want to delete these rows from the DataTable (Having X - Y rows).

What is the best and fast way to do it?

I don't know if it is better to create a new DataTable to have the Y and after that bind them to a ViewList or something else?

I'm also looking for example in code how to select/delete rows from DataTable.

View 1 Replies

C# - Updating Rows In DataTable?

Nov 22, 2010

I'm trying to update fields in a DataTable. The field I'm trying to edit is a date, I need to format it.

foreach (DataRow row in dt.Rows)
{
string originalRow = row["Departure Date"].ToString(); //displays "01/01/2010 12:00:00 AM"
row["Departure Date"] = DateTime.Parse(row["Departure Date"].ToString()).ToString("MM/dd/yyyy");
string newRow = row["Departure Date"].ToString(); //also displays "01/01/2010 12:00:00 AM"
}

How come this isn't getting updated?

View 2 Replies

Forms Data Controls :: GridView Updating Having Datasource Datatable?

Jul 16, 2010

I am making shopping cart application.On Viewing Shopping Cart,when i try to update the quatity of product column it permit me to edit but wn i click update link.the gridview disappears wid all products.send me some code snippet in C# as i want only quantity column to be editable.I am using the following code:in Code behind File

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;

[code]...

View 4 Replies

DataSource Controls :: Concatenating Rows From Another Two Tables

Apr 13, 2010

I have a problem where I would like to get a comma-separated list of items from a couple of tables as part of a set of results. All the searching I've done so far has produced results for dealing with one or two tables. I have four, and can't get my head around how to adapt the sql to deal with it.

I have the following layout:

*Table_Castings*
+---- CastingID {PK}
| MouldID

| SerialNo

| CastRef

| MeltCode

| Signature

|

|

| *Table_CastCertificates* *Table_Certificates*

| CertificateID {PK} ----------- CertificateID {PK}

+---- CastingID {PK} Description

FileID -----------------+

|

|

*Table_CertificateFiles* |

FileID {PK} -------------+

FullLocation

The results I would like include the following columns:

CastingID, MouldID, SerialNo, CastRef, MeltCode, [Certificates],

Where Certificates is a comma separated list of Description + " " + FullLocation records. (What I'll actually do is add http:// and other html codes to make FullLocation a hyperlink, but I can do that.)

Some SQL I've already got is this:

DECLARE @str VARCHAR(500)

SELECT @str = COALESCE(@str + ', ','') + '<a href="http://' + Table_CertificateFiles.FullLocation + '">' + Table_Certificates.Description + '</a>'

FROM Table_CastCertificates INNER JOIN

Table_Certificates ON Table_CastCertificates.CertificateID = Table_Certificates.CertificateID INNER JOIN

Table_CertificateFiles ON Table_CastCertificates.FileID = Table_CertificateFiles.FileID

WHERE (CastingID = 45)

SELECT output = @str

This actually gives all records in the for the specific casting, but I keep getting an error at the "=" in @str = COALESCE when I try joining it to another query to get each casting.

View 3 Replies

DataSource Controls :: Matched Rows On Two Tables

Jun 17, 2010

[Code]....

View 2 Replies

DataSource Controls :: How To Add New Rows To Datatable Using Loop

Feb 26, 2010

iam working with gridview in asp.net3.5,Sqlserver2008 I am retrieving data from a SP into a datatable.i need to store this table into gridview. but am getting the last row from my datatable into my gridview.

here i need to add each row to the datatable.

my grid is like this:

[Code]....

View 5 Replies

DataSource Controls :: Serialize A Datatable With 700,00 Rows?

Jun 24, 2010

I get the usual system.outofmemoryexception with the code below.

Is there a way to do this in small chunks?

public static void Serialize(DataTable dt, string filename)
{
FileStream fs = new FileStream(filename, FileMode.Create);
BinaryFormatter bf = new BinaryFormatter();
try
{
bf.Serialize(fs, dt);
fs.Close();
}
catch (Exception)
{
fs.Close();
fs.Dispose();
File.Delete(filename);
}
}

View 3 Replies

DataSource Controls :: Checking Duplicate Rows In Tables W/o PK

Mar 12, 2011

I have 5 tables as follows

as it can be seen from diagram, I have one table ie.patientdetails with Pid as primary key and other 4 tables have pid which is foreign key related to Pid in patient details.

the problem is that when if a test data is filled for say patient with Pid as 1, the data is saved nicely in required tables

If i try doing that again for same patient then a duplicate is created in test tables with pid as 1.

View 7 Replies

Web Forms :: Adding Rows To Datatable

Dec 6, 2011

I have added a row to a datatable and displayed this datatable by binding it to gridview.. Later if i add another row to the same table, the data table displays only the recently added row.. I need to display the previously added row along with the newly added row.. How to do this?

View 1 Replies

DataSource Controls :: System.Data.Datatable Updating SQL Server Image Field

Jul 1, 2010

I have a datatable for which i'm defining a dataadapter. I'm specifying an updatecommand with sqlparameters for the dataadapter I set the updatecommand's parameters using the following overload:

[Code]....

The length 16 is used because this is the length of the field according to sql (the image datafield is a pointer of size 16) I noticed .Net is actually truncating the string because of the length i'm setting. An image of size 3kb will properly upload if we set the length field to be greater than 3kb The question I have is what is the proper value (or strategy) to use in order to set for the length field so that ALL images will properly update to the database, with each using the appropriate size.

I guess i could theoretically set the length to be maxint, but this seems sloppy. Looking at sqlparameter documentation i didnt see an 'unlimited' or 'default' length i could set, which would allow each update statement called to use the appropriate size for the data length for that row.

View 1 Replies

DataSource Controls :: Update Datatable Changed Rows Only?

May 24, 2010

I am using untyped database bind to gridview in an edit form. Now user makes some changes to that datatable (update, delete, insert). How do I detect which rows he changes and which rows he deleted (so I drop them from DB). I know it can be done easily via table adapters but I am supporting a previously built app using untyped datatables/datasets.

View 9 Replies

DataSource Controls :: Adding The Same Data Values Into 2 Tables

Apr 23, 2010

i have an insert statement, and what i would like to do iswhen the value of table1 is entered, that value enters into table 2, so for example, heres my insert statement

INSERT INTO Cards (Name, Desc, id) VALUES ( @Name, @Desc, @id) INSERT INTO CardTP (NameSet, Desc, id)

Now, what i would like to do is that, i will specify all those individual values myself, BUT, when it now comes to the "id" field, when an id is entered for the "Cards" table, the SAME id should also be entered in the id column of the "CardTP" table. how i could enter the value of one table, into another tables row (having the same value) as i want the Cards and CardsTP table to be related in the id fields.

View 3 Replies

DataSource Controls :: Adding Columns To The Tables In The DB Dynamically?

Jun 30, 2010

Dim AlterTable As String = "alter table [Upload] add [Country] nvarchar (50) default 0 NOT NULL,[Address] int default 0 NOT NULL"

Dim connection As Data.SqlClient.SqlConnection
connection = New Data.SqlClient.SqlConnection()
connection.ConnectionString = ConfigurationManager.ConnectionStrings("ASPNETDBconnectionString1").ConnectionString
Dim cmdUpdating1 As New Data.SqlClient.SqlCommand(AlterTable, connection)
cmdUpdating1.CommandType = CommandType.Text
connection.Open()
cmdUpdating1.ExecuteNonQuery()
connection.Close()

This is the code which I am using for altering the number of columns in a table in the DB. so with this code i am able to add new coulmns dynamically. Now my major requirement in this is to obtain the headercount from the user( say "telephone number" and "language") and based on it generate the columns dynamically in the table in the DB.

View 12 Replies

DataSource Controls :: Adding Multiple Tables To The Array?

Feb 4, 2010

I am using ASP.NET 2.0, C# and Sql Server 2005.I have 2 tables retruned by the stored procedure to the application. I am returning an Array from my datalayer to my bussiness layer and then to my UI layer.I have added the first table into the array and passing it to the UI layer. This is my current code:

[Code]....

How to pass the second table details to the same array, NameArrayKeyEntity .

View 3 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 :: Check Datatable Rows For Existing Item?

Jun 12, 2010

I have one problem with my shopping cart that I really can't figure out all by myself.I want, if a item already exist in the datatable, the quantity to be updated for that item with the new number instead of creating the same item again.I have done a foreach loop because I think that is where I should start.Notes: MyRow[3] is the column holding the quantity.Code:

[Code]....

//Bengt

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

Web Forms :: Adding Rows To Datatable And Binding It In GridView

Dec 9, 2011

I have a gridview with empty data template. In this empty data template i have a table(HTML) with 4 columns. When user enters data i want to save this in a datatable temporarily at a button click event.. Again if user wants to add one more rows data that also should be added to the same table where i added previous row data. So now the datatable has 2 rows. Like this he may add any no of rows. What i want is all the rows should be displayed when i bind datatable to gridview..At the click event i am adding 1 row at a time to the datatable

View 1 Replies

SQL Server :: Adding Rows To Multiple Primary Keyed Tables?

Jul 27, 2010

I am accessing rows in an SQL database table based upon the contents of 2 Primary key columns. But, I cannot insert new rows in the table when the content in one of the new Primary key columns already exists in another row. I get an error message that says: "Violation of PRIMARY KEY constraint 'PK_ReferendumVoters'. Cannot insert duplicate key in object 'dbo.ReferendumVoters'. The statement has been terminated."

The reason why this error is occurring is because I first stored "Referendum 1" in one column along with "me" in the second column of a new row for a "ReferendumVoters" table. Then, I attempted to insert a new row with the same "Referendum 1" string in the first column along with a different name in the second column. But, it will not let me do this even though I created a new index that defines the two columns as unique. Is there any way that will enable me to do this?

View 5 Replies

DataSource Controls :: Adding A DateTime Field To A DataTable?

May 20, 2010

I'm looping through an ArrayList and creating a column in a DataTable from each field. One of my fields is a DateTime field, and I've noticed that when I create the columns, it's being changed to a String, but I need it to still be a DateTime field for sorting. I'm trying to do this, but it's not quite working.

[Code]....

View 3 Replies

DataSource Controls :: Delete The Rows Present In The DataTable From IEnumerable DataRow

Jul 22, 2010

I want to delete the rows present in the DataTable by using LINQ (with out looping)

The deleted rows will be come from a LINQ as below

IEnumerable<DataRow> MobileQuery = (from d in dtBillDetail.AsEnumerable()
where (String.Compare(d.Field<string>("Destination"), "MOBILE", StringComparison.InvariantCultureIgnoreCase) == 0) select d );

The DataRows present in the "MobileQuery" should be deleted in the DataTable "dtBillDetail"

View 1 Replies

DataSource Controls :: Adding List Item Collection To Datatable?

Jul 7, 2010

I have a list item collection. How to add this list item collection to a datatable.

The list item collection has the following fields:

Student Name, Maths Mark
John 20
Mac 30
John 35

I want to create a html table from the data table, which is grouped on the Student Name field.

View 2 Replies

DataSource Controls :: Limiting String Length When Adding New DataTable Row?

Mar 13, 2011

I need to limit the length of the string that load into a DataTable that is being used to display. The data I am loading is coming from another DataTable. How do I shorten row["CG_GalleryName"] contents to 24 characters.

Convert.ToString(row["CG_GalleryName"]) -- how do I set this length to 24 characters? Using it in the below code.

if (Convert.ToInt16(row["rnum"]) == 1)
{
dr = GLinks.NewRow();
dr["rnum"] = row["rnum"];
dr["L_URL"] = row["L_URL"];
dr["CG_GalleryName"] = row["CG_GalleryName"];
dr["L_Picture"] = row["L_Picture"];
GLinks.Rows.Add(dr);

View 8 Replies

DataSource Controls :: Create Interface For Adding Users - Datatable Or Dataset

May 3, 2010

I need to create an interface for adding users to .Net Membership DB through an existing database. My Idea is to read each row from database from existing users table in a datatable and then iterate through each row and add it to new database. I cannot directly copy the rows from existing users table because the password stored in .Net Membership provider is in ir-reversible hash code and hashing is done through encryption algorithm present in front end code. My User count is huge (in millions).So what should i use to read the records, Dataset or datatable. Also tell what is the max number of rows it can hold.

View 3 Replies







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