473,788 Members | 2,988 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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);
OleDbDataAdapte r myDA = new OleDbDataAdapte r(myCommand);
DataSet myDS = new DataSet();
myDA.Fill(myDS, "Companies" ); // CAN THIS BE REMOVED ?

DataRow myRow = myDS.Tables["Companies"].NewRow();
myRow["CompanyNam e"] = "Widget Corp.";
myRow["StockSymb"] = "WID";
myDS.Tables["Companies"].Rows.Add(myRow );
OleDbCommandBui lder mBuild = new OleDbCommandBui lder(myDA);
myDA.Update(myD S, "Companies" );

}
Nov 15 '05 #1
5 7033
> 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);
OleDbDataAdapte r myDA = new OleDbDataAdapte r(myCommand);
DataSet myDS = new DataSet();
myDA.Fill(myDS, "Companies" ); // CAN THIS BE REMOVED ?
myDA.FillSchema ( myDS, SchemaType.Sour ce, "Companies" );
myDT= myDS.Tables[ "Companies" ];
DataRow myRow = myDS.Tables["Companies"].NewRow();
myRow["CompanyNam e"] = "Widget Corp.";
myRow["StockSymb"] = "WID";
myDS.Tables["Companies"].Rows.Add(myRow );
OleDbCommandBui lder mBuild = new OleDbCommandBui lder(myDA);
myDA.Update(myD S, "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 );
DataColumnColle ction columns = table.Columns;
DataColumn Column = columns.Add( PKID_FIELD, typeof( System.Int32 ));
Column.AllowDBN ull = false;
Column.AutoIncr ement = 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);
OleDbDataAdapte r myDA = new OleDbDataAdapte r(myCommand);
DataSet myDS = new DataSet();
myDA.Fill(myDS, "Companies" ); // CAN THIS BE REMOVED ?


myDA.FillSchema ( myDS, SchemaType.Sour ce, "Companies" );
myDT= myDS.Tables[ "Companies" ];
DataRow myRow = myDS.Tables["Companies"].NewRow();
myRow["CompanyNam e"] = "Widget Corp.";
myRow["StockSymb"] = "WID";
myDS.Tables["Companies"].Rows.Add(myRow );
OleDbCommandBui lder mBuild = new OleDbCommandBui lder(myDA);
myDA.Update(myD S, "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 );
DataColumnColle ction columns = table.Columns;
DataColumn Column = columns.Add( PKID_FIELD, typeof( System.Int32 ));
Column.AllowDBN ull = false;
Column.AutoIncr ement = 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
2927
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
2208
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 taken from database are very large, and filling DataSet bounded to this DataGrid takes some time, a decided to put fill logic into new thread. And so method running in this thread clears only this DataSet bounded to DataGrid and fills it once more...
0
10847
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 "result" into a single sql table that has an auto-increment and PK column called ID, as well as the 5 columns from the dataset. Any suggestions on a way to perform the insert of the "result" dataset into the sql table?
4
6221
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 ? Thx and regards Fabian
3
2004
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 tables that are already pouplated. When my code tries to fill the 4th table, ReportData, I receive the following error message: Invalid object name 'tmpPROJECTINFO'. Invalid object name 'tmpContacts'. Invalid object name 'tmpRECEIVEREC'. Can...
5
10904
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, objCon) SQL = "INSERT INTO linkinfo VALUES('" & Sno & "','" & Website & "','" & Path & "')" & _ "('" & Keywords & "','" & MeWebsite & "','" & MePath & "','" &
0
1428
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 message that says "object reference not set to an instance of an object" when I return the varchar field." The detailed error message is below. Server Error in '/BIC_WEB_TEST' Application....
0
1449
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 great community here, without you i bet many of us would not succeed that fast. So now to my problem :)
3
3789
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 the code wich i have use. SqlConnection conn = new SqlConnection(ConnectionString); String S = "Insert into Area values ('" + textBox1.Text.ToString().Trim() + "')"; SqlCommand command = new SqlCommand(S); ...
0
9498
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10364
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10172
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9967
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.