473,387 Members | 1,483 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Ado.net : How to insert a row without filling the dataset ?

Hello,

Is it necessary to initially fill a dataset to be able to add a new row
to the dataset and then update the undercover database ?
(In the case of a very large database, this would mean that all the
database content should be loaded before beeing able to add a new row,
and i don't want to load anything...)

Is it possible in the following code to remove the
"// CAN THIS BE REMOVED ?"
line ?
Sample Code :
**************

public static void Main() {

SqlConnection myConn = new SqlConnection("...");
SqlCommand myCommand = new SqlCommand( "Select * from Company", myConn);
OleDbDataAdapter myDA = new OleDbDataAdapter(myCommand);
DataSet myDS = new DataSet();
myDA.Fill(myDS, "Companies"); // CAN THIS BE REMOVED ?

DataRow myRow = myDS.Tables["Companies"].NewRow();
myRow["CompanyName"] = "Widget Corp.";
myRow["StockSymb"] = "WID";
myDS.Tables["Companies"].Rows.Add(myRow);
OleDbCommandBuilder mBuild = new OleDbCommandBuilder(myDA);
myDA.Update(myDS, "Companies");

}
Nov 15 '05 #1
5 7009
> Is it necessary to initially fill a dataset to be able to add a new row
to the dataset and then update the undercover database ?
(In the case of a very large database, this would mean that all the
database content should be loaded before beeing able to add a new row,
and i don't want to load anything...)
Yes, it is possible.
Is it possible in the following code to remove the
"// CAN THIS BE REMOVED ?"
line ?


No because your dataset schema is not defined.
You might manullay add columns to the dataset's table.
--
Miha Markic -RightHand .NET consulting & development.
Nov 15 '05 #2
How to get a dataset schema from a dataadapter without filling the
dataset with records using the .Fill method from the dataAdapter object
?

I would like to do it without doing the FILL instruction, so the
response time to add a new row does not depend on the size of the
database...
Thanks,
Cybertof.


In article <ud*************@tk2msftngp13.phx.gbl>, ms**@spin.si says...
Is it possible in the following code to remove the
"// CAN THIS BE REMOVED ?"
line ?


No because your dataset schema is not defined.
You might manullay add columns to the dataset's table.

Nov 15 '05 #3
> Is it necessary to initially fill a dataset to be able to add a new row
SqlConnection myConn = new SqlConnection("...");
SqlCommand myCommand = new SqlCommand( "Select * from Company", myConn);
OleDbDataAdapter myDA = new OleDbDataAdapter(myCommand);
DataSet myDS = new DataSet();
myDA.Fill(myDS, "Companies"); // CAN THIS BE REMOVED ?
myDA.FillSchema( myDS, SchemaType.Source, "Companies");
myDT= myDS.Tables[ "Companies" ];
DataRow myRow = myDS.Tables["Companies"].NewRow();
myRow["CompanyName"] = "Widget Corp.";
myRow["StockSymb"] = "WID";
myDS.Tables["Companies"].Rows.Add(myRow);
OleDbCommandBuilder mBuild = new OleDbCommandBuilder(myDA);
myDA.Update(myDS, "Companies");


As the other reply to your post pointed out you could also add the columns
as in this excerpt from the Duwamish sample:

DataTable table = new DataTable( CUSTOMERS_TABLE );
DataColumnCollection columns = table.Columns;
DataColumn Column = columns.Add( PKID_FIELD, typeof( System.Int32 ));
Column.AllowDBNull = false;
Column.AutoIncrement = true;
columns.Add( EMAIL_FIELD, typeof( System.String ));
columns.Add( PASSWORD_FIELD, typeof( System.String ));
columns.Add( NAME_FIELD, typeof( System.String ));
columns.Add( ADDRESS_FIELD, typeof( System.String )).AllowDBNull= false;
columns.Add( COUNTRY_FIELD, typeof( System.String )).AllowDBNull= false;
columns.Add( PHONE_FIELD, typeof( System.String )).AllowDBNull= false;
columns.Add( FAX_FIELD, typeof( System.String ));
this.Tables.Add( table );
Nov 15 '05 #4
Thanks Miha Markic & Empire City.

In think i prefer to extract the schema from the existing database, so
in case of small inner database schema change (type change for example)
, the code would "update itself dynamically" extracting the schema on
the fly from the database.
Regards,
Cybertof.

In article <hF*******************@twister.nyc.rr.com>, a@b.com says...
Is it necessary to initially fill a dataset to be able to add a new row

SqlConnection myConn = new SqlConnection("...");
SqlCommand myCommand = new SqlCommand( "Select * from Company", myConn);
OleDbDataAdapter myDA = new OleDbDataAdapter(myCommand);
DataSet myDS = new DataSet();
myDA.Fill(myDS, "Companies"); // CAN THIS BE REMOVED ?


myDA.FillSchema( myDS, SchemaType.Source, "Companies");
myDT= myDS.Tables[ "Companies" ];
DataRow myRow = myDS.Tables["Companies"].NewRow();
myRow["CompanyName"] = "Widget Corp.";
myRow["StockSymb"] = "WID";
myDS.Tables["Companies"].Rows.Add(myRow);
OleDbCommandBuilder mBuild = new OleDbCommandBuilder(myDA);
myDA.Update(myDS, "Companies");


As the other reply to your post pointed out you could also add the columns
as in this excerpt from the Duwamish sample:

DataTable table = new DataTable( CUSTOMERS_TABLE );
DataColumnCollection columns = table.Columns;
DataColumn Column = columns.Add( PKID_FIELD, typeof( System.Int32 ));
Column.AllowDBNull = false;
Column.AutoIncrement = true;
columns.Add( EMAIL_FIELD, typeof( System.String ));
columns.Add( PASSWORD_FIELD, typeof( System.String ));
columns.Add( NAME_FIELD, typeof( System.String ));
columns.Add( ADDRESS_FIELD, typeof( System.String )).AllowDBNull= false;
columns.Add( COUNTRY_FIELD, typeof( System.String )).AllowDBNull= false;
columns.Add( PHONE_FIELD, typeof( System.String )).AllowDBNull= false;
columns.Add( FAX_FIELD, typeof( System.String ));
this.Tables.Add( table );

Nov 15 '05 #5
Hi,

In addition to this two ways, there is another one. You might use
strongtyped dataset (created at design time).
--
Miha Markic - RightHand .NET consulting & development
Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Abareblue | last post by:
I have no clue on how to insert a record into access. here is the whole thing using System; using System.Drawing; using System.Collections; using System.ComponentModel;
1
by: Krzysztof Karnicki | last post by:
I have such a problem… I have create my custom DataGridColumn inheriting from System.Windows.Forms.DataGridColumnStyle on using it on DataGrid, to show rows painted by me self. Because dates ...
0
by: a | last post by:
I've read and split a delimited text file into a dataset. It looks fine in a datagrid (5 columns and 5,000 rows), but I've been trying, without success, to then insert the resulting dataset called...
4
by: Fabian | last post by:
Hello, i need an example to fill a Dataset Object without a Database. I want to save Strings, like a Database for using it in a Crystal Report. Does anyone have an example for me please ? ...
3
by: crjunk | last post by:
I have a 3 table in my DataSet that I'm filling with data. After I've filled these 3 tables, I'm then trying to run a query that will fill a 4th table in the DataSet with data from the three...
5
by: Pankaj | last post by:
Hi i am inserting the data into database throught variables. On click event of button m using this code: Dim objCon As New OleDbConnection(CONNECTION) Dim objCmd As New OleDbCommand(SQL,...
0
by: Derek Vincent | last post by:
Why am I having problems filling my dataset when I select fields of type varchar(350) from interbase? I can fill the dataset when I select every other field in the table but I receive and error...
0
by: ReneMarxis | last post by:
Hello all first let me say i start getting an idea on how powerful data binding is. You can hold your code as short as possible and also have a pretty big flexibility. Also thanks to this...
3
by: buterfly0707 | last post by:
hi evryone.. i want to get the text box value to list box . And also i want this textbox value enter into the dabasex table called Area and @ th esame time insert this value to List box. here is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.