Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 9th, 2006, 04:03 AM
Registered User
 
Join Date: Feb 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default XML into SQL

i m new to C# and im trying to import a xml file from local disk and load all the elements into a sql table .. so here is my code and i keep gettin this error Update Object must implement IConvertible

Code:
public static int LoadExternal(string Filename)
        {
            int Sflag = 0;

            SqlConnection SecondSiteCon = new SqlConnection(GlobalConstants.SecondSiteConnectionString);

            XmlDocument AccountHoldersxd = new XmlDocument();
            XmlNode ndAccountHolders;

            AccountHoldersxd.Load(Filename);

            XPathNavigator nav;


            ndAccountHolders = AccountHoldersxd["AccountHolders"];

            nav = AccountHoldersxd.CreateNavigator();
            nav.MoveToRoot();
            nav.MoveToFirstChild();

            try
            {
                SecondSiteCon.Open();

                SqlCommand AddToDB = new SqlCommand("Exec AddNewAccountHolder @AccountHolder, @FirstName, @LastName, @Gender, @BirthDate, @CreditCardNumber, @ExpiryDate", SecondSiteCon);
                AddToDB.Parameters.Add("@AccountNumber", SqlDbType.Int);
                AddToDB.Parameters.Add("@FirstName", SqlDbType.VarChar);
                AddToDB.Parameters.Add("@LastName", SqlDbType.VarChar);
                AddToDB.Parameters.Add("@Gender", SqlDbType.Char);
                AddToDB.Parameters.Add("@BirthDate", SqlDbType.DateTime);
                AddToDB.Parameters.Add("@CreditCardNumber", SqlDbType.VarChar);
                AddToDB.Parameters.Add("@ExpiryDate", SqlDbType.DateTime);

                AddToDB.CommandType = CommandType.StoredProcedure;

                AddToDB.Transaction = SecondSiteCon.BeginTransaction();

                try
                {    
                    if (ndAccountHolders != null)
                    {
                        XmlNode ndAccountHolder;
                        ndAccountHolder = ndAccountHolders.FirstChild;


                        //                    foreach(XmlNode nd in ndAccountHolders.ChildNodes)
                        //                    {
                        //                    string mCreditCardNum;
                        //                    mCreditCardNum = nd["CreditCardNumber"].Value.ToString();
                        //                    string EncryptedCCNum;
                        //                    EncryptedCCNum = DESLibrary.ToBase64String(mCreditCardNum,"AABBCCDD");
                        while(ndAccountHolder != null)
                        {
                            AddToDB.Parameters["@AccountNumber"].Value = ndAccountHolder["AccountNumber"];
                            AddToDB.Parameters["@FirstName"].Value = ndAccountHolder["FirstName"];
                            AddToDB.Parameters["@LastName"].Value = ndAccountHolder["LastName"];
                            AddToDB.Parameters["@Gender"].Value = ndAccountHolder["Gender"];
                            AddToDB.Parameters["@BirthDate"].Value = ndAccountHolder["BirthDate"];
                            AddToDB.Parameters["@CreditCardNumber"].Value = ndAccountHolder["CreditCardNumber"];
                            AddToDB.Parameters["@ExpiryDate"].Value = ndAccountHolder["ExpiryDate"];

                            ndAccountHolder = ndAccountHolder.NextSibling;


                            AddToDB.ExecuteNonQuery();

                            AddToDB.Transaction.Commit();
                        }            

                                    //                    }
                    }


                }
                catch (Exception ex)
                {
                    AddToDB.Transaction.Rollback();
                    throw ex;
                }

            }
            finally
            {
                SecondSiteCon.Close();
            }

        return Sflag;

           }


Reply With Quote
  #2 (permalink)  
Old February 9th, 2006, 10:19 AM
Friend of Wrox
Points: 3,489, Level: 24
Points: 3,489, Level: 24 Points: 3,489, Level: 24 Points: 3,489, Level: 24
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Central, NJ, USA.
Posts: 1,102
Thanks: 0
Thanked 2 Times in 2 Posts
Default

This error is usually related to data types not being correct.

For example: ndAccountHolder["AccountNumber"] could be a string your trying to assign to an int. Check which are wrong and convert them over.



Hal Levy
Please do your own homework.
I am here to help you, not do it for you.
I do not have sample code for anything
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Relational SQL Data to XML - Vet SQL/ASP - New XML JimiTheJett XML 1 December 4th, 2008 06:06 PM
SQL Server 2005 XML: FOR XML PATH -> cdata? stoves SQL Server 2005 1 July 8th, 2008 02:40 AM
SQL to XML toddw607 SQL Server 2000 1 March 20th, 2007 03:39 AM
Export SQL To XML shillr SQL Server 2000 0 August 1st, 2006 10:14 AM
XML dataisland / sql XueXue XML 2 November 11th, 2004 02:25 PM



All times are GMT -4. The time now is 05:48 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.