index > .NET Framework Data Access and Storage > multiple to single - oracle help req.

multiple to single - oracle help req.

hi! im not sure if im posting at the right forum but here is my problem..

in my program i need to insert multiple columns to a single row.. the multiple column is in a different database (remote) and the single column is in my local. how could i do this?

thanks!

Xeleste

where are you inserting these columns? in a datatable? Datagridview?

for what you are describing, you would need to fill a dataset using the DataAdapter (SQL or OleDb) with the records, as it retrieves everything (All records and its columns) and then insert your data into that/modify it then finally update the database using the Update(theDataSet) of te DataAdapter

you need to explain more so we can help you :-)




Need 2 be back @ MS - MS All the way! Follower since 1995 MS Super Evangelist| MSDN Forums Moderator
ahmedilyas

here is the full background to my problem....

i have two database.. SQL2005 and Oracle. The program will get from oracle the grades of the student and insert it into a table in sql. i would like to insert it into a datatable. my main problem is in oracle the results will be in columns and it would be inserted in a row in SQL. for example the student has 5 subjects, in oracle that would be seen as 5 rows it then would be inserted to sql in a single row. it would depend on the student id.

i only could insert one result because when i try to insert the next result it ends up in the next row..

hope you could help me.. thanks!

Xeleste

you need to pretty much retrieve all the data/columns from the first database. Then you need to generate an INSERT statement into SQL for example (your destination database). These syntax below will work on SQL:

 

INSERT INTO tableName (field1, field2) VALUES (@p1, @p2)

 

of course replace the tablename/fieldnames etc... and add the number of fields to add data for 1 record appropriately. Currently it only has 2 fields.

Here is an example of inserting data into a database in SQL using 2 fields with given values. Be sure to import the System.Data.SqlClient namespace:



SqlCommand theSQLCommand = new SqlCommand("INSERT INTO tableName (field1, field2) VALUES (@p1, @p2)");
theSqlCommand.Connection = new SqlConnection(connectionString);
 
SqlParameter p1 = new SqlParameter("@p1", SqlDbType.Int);
p1.Value = "1";
SqlParameter p2 = new SqlParameter("@p2", SqlDbType.NVarChar, 50);
p2.Value = "hello";
 
theSqlCommand.Parameters.Add(p1);
theSqlCommand.Parameters.Add(p2);
 
theSqlCommand.Connection.Open();
theSqlCommand.ExecuteNonQuery();
theSqlCommand.Connection.Close();

 

 

this simply creates 2 parameters, an Insert statement to insert the values for 1 record and executes the command. Its best practice to use Stored Procedures for Sql since its safer and securer but this is something for another day for you to learn perhaps, the above was a simple quick example.

 

As for creating a dataTable for example, similar thing would apply EXCEPT you need to again, get the columns you need, their values, and create a datatable with the amount of columns you like:

 

DataTable theDataTable = new DataTable();

theDataTable.Columns.Add("columnName");

theDataTable.Columns.Add("columnName2");

//Add a record:

object[] theRecord = new object[] {"Field1Value", "Field2Value"};

theDataTable.Rows.Add(theRecord);

 

this will create the columns in the datatable, and add a record of data, with the column values. You can also "strongly type" the datatable, meaning, each column must be of a specific data type, like string, or int etc... Example:

theDataTable.Columns.Add("columnName", System.Type.GetType("System.String"));

Does this help at all?




Need 2 be back @ MS - MS All the way! Follower since 1995 MS Super Evangelist| MSDN Forums Moderator
ahmedilyas
it does help but still im a bit confused.. will this work when im using SQL and oracle?
Xeleste

the insert into etc... is for SQL. The DataTable has no relevance between SQL and oracle... its just an in memory storage to store your data from one database perhaps into the datatable.

I have never used oracle but can give you some logic in what to do to retrieve records and insert into SQL. Basically you stated that (please correct me)oracle gets a record information in row(view) correct? So what you have to do is to retrieve those "rows" as 1 record, perhaps with the aid of maybe a dataAdapter some datareader for oracle.

I may move this thread to the appropriate forum if you need to know about how to retrieve data from oracle then apply my solution once you have retrieved data, and once the solution I have given has been applied, you will be inserting the record(s) into SQL




Need 2 be back @ MS - MS All the way! Follower since 1995 MS Super Evangelist| MSDN Forums Moderator
ahmedilyas

I am actually new to oracle myself... its okay if you will move this thread.. thanks for the help! i really appreciated it!

 

Xeleste
reply 7

You can use google to search for other answers

 

More Articles

• how to read .html file and save in asp.net
• Single DateSource - Multiple Databases
• Help C# SQLTABLES
• OleDbCommand.Update method bug - parameter values overlap
• DataView with DateTime comparation
• Oracle Real Application Cluster Support
• Access database problem!!!
• retrieve schema info for a SQL statement in sql datatypes
• XML Schema Help with FIX 4.4
• Need to keep value after transforming to different field type fro...
Bookmark and Share
Welcome to Bokebb   New Update  
 

New Articles

• DataSet Merging
• Master Detail Records
• Microsoft Oracle .NET Data Provider Perf
• mapping issue with sql executenonquery m
• The partner transaction manager has disa
• Need to keep value after transforming to
• Accessing ADO .Net DLL from C++ code
• Typed Dataset Question #2
• can't insert data into database
• stored procedure Parameter information
• Dynamic connection strings.. possible?
• high performance ADO.NET
• Add rows to DataTable
• using vs.net2005 dataset
• I had the same problem

Hot Articles

• Data Access Page
• sqlserver 2005 connection with vb expres
• How to Insert the records from DBF into
• Geting Total Number of Rows in a Recordset
• parameter Array in Stored Procedure
• edit/update on detailsview throws except
• catcha sqlexception and column
• Update issue vb.net2005 express - SQLSer
• Populate DataSet from CSV
• Can't figure out this error message
• Database Structure design and User Inter
• UPdating a SQL table using dataset from
• How to control root node name for the Da
• Inserting a row duplicates this row
• Could not search SQL with DateTime compa

Recommend Articles

• How to force a single line per data in a
• Typed DataSet Class not exposing its mem
• How to call a aspx page from a exe file
• Desiging Data Access
• Connecting to Access DB
• Connection pooling
• Database update works as console app, fa
• Returning DataReaders
• Best way to create multiline T-SQL in .N
• DB_E_BADROWHANDLE(0x80040E04)]??when usi
• Currency data / Bound field in a Datavie
• transaction problem
• Connection Timeout
• Dropdownlist Binding
• Problem with calculated column - does no