Showing posts with label schema. Show all posts
Showing posts with label schema. Show all posts

Tuesday, March 20, 2012

Retrieving excle schema

HI all,
How can I retrieve the schema of set range froman excle spreadsheet. The
range has the valid data that I need inorder to create a staging table, But
once the staging table is created I do not want to recreate it everytime
with the select into, as i am setting indexes and triggers on this staging
table. Once the staging table is created it would mostliley be used from
that point on/
Thanks
RobertAfter you've created the staging table using SELECT...INTO script it out
using your favourite editing tool, then in your script replace the
SELECT...INTO statement with a CREATE TABLE and an INSERT...SELECT statemens
.
On scripting out SQL objects' DDL:
http://www.aspfaq.com/etiquette.asp?id=5006
ML
http://milambda.blogspot.com/

Monday, March 12, 2012

Retrieving Column Name and Value for each row using GetSchemaTable

I know I can iterate through the schema table using the following.

Can I grab the actual value of each field while looping through the rows and columns?

schemaTable = reader.GetSchemaTable();

foreach (DataRow myDataRow in schemaTable.Rows)

{

foreach (DataColumn myDataColumn in schemaTable.Columns)

{

Console.WriteLine(myDataColumn + "= " + myDataRow[myDataColumn.ColumnName].ToString() );

}

}

An example is if one of the columns in the schema is called Firstname I would like to return:

Row 1

column name = Firstname

value= Bob

column name = Lastname

value= Smith

Row 2

column name = Firstname

value= Greg

column name = Lastname

value= Jones


What about:


int i=0;

foreach (DataRow myDataRow in schemaTable.Rows)

{

Console.WriteLine(string.Format("Row {0}", (string)(i++));

foreach (DataColumn myDataColumn in schemaTable.Columns)

{

Console.WriteLine(string.Format("Column Name = {0}",myDataColumn.ColumnName);

Console.WriteLine(string.Format("value = {0}" , myDataRow[myDataColumn.ColumnName].ToString());

}

}

Jens K. Suessmeyer.

http://www.sqlserver2005.de

|||

Thanks this works for me.