Showing posts with label xml. Show all posts
Showing posts with label xml. Show all posts

Friday, March 30, 2012

Inserting a default Value

I have populated an SQLdata table from an XML datasource usinmg the bulk command. In my SQL table is a new column that is not in the XML table which I would like to set to a default value.

Would anyone know the best way to do this. So far I can's see how to add this value in the Bulk command. I am happy to create a new command that updates all the null values of this field to a default value but can't seem to do this either as a SQLdatasource or a APP Code/ Dataset.

Any suggestions or examples where I can do this.

Many thanks in advance

A DataColumn has a DefaultValue property - seeMSDN for usage:

private void MakeTable()
{
// Create a DataTable.
DataTable table = new DataTable("Product");

// Create a DataColumn and set various properties.
DataColumn column = new DataColumn();
column.DataType = System.Type.GetType("System.Decimal");
column.AllowDBNull = false;
column.Caption = "Price";
column.ColumnName = "Price";
column.DefaultValue = 25;

// Add the column to the table.
table.Columns.Add(column);

// Add 10 rows and set values.
DataRow row;
for(int i = 0; i < 10; i++)
{
row = table.NewRow();
row["Price"] = i + 1;

// Be sure to add the new row to the
// DataRowCollection.
table.Rows.Add(row);
}
}

Monday, March 26, 2012

Insert XML RAW's output to a table

Under SQL 2000 i would like to convert and XML RAW output to text type
by using "convert" and/or insert the data into a table, is this
posible?
i.e. this statement runs ok under SQL 2k5 but fails under SQL 2k
SELECT CONVERT( text, (SELECT * FROM MyTable FOR XML RAW) )
SQL2000 reports:
-- Msg 170, Level 15, State 1, Line 1
-- Line 1: Incorrect syntax near 'XML'.
Thanks in advance.
Rod wrote:

> i.e. this statement runs ok under SQL 2k5 but fails under SQL 2k
> SELECT CONVERT( text, (SELECT * FROM MyTable FOR XML RAW) )
> SQL2000 reports:
> -- Msg 170, Level 15, State 1, Line 1
> -- Line 1: Incorrect syntax near 'XML'.
Have you tried to select into a variable first and then convert that
variable?

Martin Honnen -- MVP XML
http://JavaScript.FAQTs.com/
|||This can't be done on the server in SQL Server 2000. You would have to use
a client connection to select the data and then push it back to the server.
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
"Martin Honnen" <mahotrash@.yahoo.de> wrote in message
news:OhRh%23m%23vHHA.4796@.TK2MSFTNGP04.phx.gbl...
> Rod wrote:
>
> Have you tried to select into a variable first and then convert that
> variable?
>
> --
> Martin Honnen -- MVP XML
> http://JavaScript.FAQTs.com/
|||On 6 jul, 23:09, "Roger Wolter[MSFT]" <rwol...@.online.microsoft.com>
wrote:
> This can't be done on the server in SQL Server 2000. You would have to use
> a client connection to select the data and then push it back to the server.
>
Found this to be true, under SQL Server 2000 it's not possible to use
XML RAW inside a subquery, trying to do it will throw an error.
(still, the same unmodified
clause may work under SQL Server 2005)
Thanks

Insert XML RAW's output to a table

Under SQL 2000 i would like to convert and XML RAW output to text type
by using "convert" and/or insert the data into a table, is this
posible?
i.e. this statement runs ok under SQL 2k5 but fails under SQL 2k
SELECT CONVERT( text, (SELECT * FROM MyTable FOR XML RAW) )
SQL2000 reports:
-- Msg 170, Level 15, State 1, Line 1
-- Line 1: Incorrect syntax near 'XML'.
Thanks in advance.Rod wrote:

> i.e. this statement runs ok under SQL 2k5 but fails under SQL 2k
> SELECT CONVERT( text, (SELECT * FROM MyTable FOR XML RAW) )
> SQL2000 reports:
> -- Msg 170, Level 15, State 1, Line 1
> -- Line 1: Incorrect syntax near 'XML'.
Have you tried to select into a variable first and then convert that
variable?
Martin Honnen -- MVP XML
http://JavaScript.FAQTs.com/|||This can't be done on the server in SQL Server 2000. You would have to use
a client connection to select the data and then push it back to the server.
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
"Martin Honnen" <mahotrash@.yahoo.de> wrote in message
news:OhRh%23m%23vHHA.4796@.TK2MSFTNGP04.phx.gbl...
> Rod wrote:
>
> Have you tried to select into a variable first and then convert that
> variable?
>
> --
> Martin Honnen -- MVP XML
> http://JavaScript.FAQTs.com/|||On 6 jul, 23:09, "Roger Wolter[MSFT]" <rwol...@.online.microsoft.com>
wrote:
> This can't be done on the server in SQL Server 2000. You would have to us
e
> a client connection to select the data and then push it back to the server
.
>
Found this to be true, under SQL Server 2000 it's not possible to use
XML RAW inside a subquery, trying to do it will throw an error.
(still, the same unmodified
clause may work under SQL Server 2005)
Thankssql

Insert xml into mssql 2000

Hi,

I have app with file selection field. Users can shoose xml file from their local hard disk and click Save. When they click save, content of xml file should be inserted into mssql 2000.

What is the most efficient way to do this using C#2005 and mssql2000?

Any good article or tutorial?

http://www.databasejournal.com/features/mssql/article.php/2204421|||http://aspalliance.com/477