Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
|
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 17th, 2007, 04:24 AM
Registered User
 
Join Date: Jan 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Used SQLCommand, but no input

Code:
public void importFile(string fileType, string fileName)
        {
            if(fileType.ToUpper() == "EXCEL")
            {
                string Excel_connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileName + ";Extended Properties='Excel 8.0;HDR=Yes;IMEX=1'";

                DataFactory = DbProviderFactories.GetFactory("System.Data.OleDb");
                DataConnection = DataFactory.CreateConnection();               
                DataConnection.ConnectionString = Excel_connectionString;              
            }

            SQLConnection = new SqlConnection(Properties.Settings.Default["TPMCSCString"].ToString());

            if(Properties.app.Default["appDebug"].ToString().ToUpper() == "TRUE")
            {
                //MessageBox.Show();
            }
        }

        public void importMode(string importType)
        {
            if(importType == "LCC")
            {
                using (DataCommand = DataConnection.CreateCommand())
                {
                    SQLCommand = SQLConnection.CreateCommand();

                    DataCommand.CommandText = "SELECT citemcode, clcc FROM [LCC$]"; //SQL Statement

                    DataConnection.Open();
                    SQLConnection.Open();

                    using (DataReader = DataCommand.ExecuteReader())
                    {
                        while (DataReader.Read())
                        {
                            if (DataReader["clcc"].ToString() != "")
                            {
                                SQLCommand.CommandText = "INSERT INTO rscLCC (LocalCollectiveCode, SpecificCode)" +
                                                        " VALUES ('" + DataReader["clcc"].ToString().Trim() + "', '" +
                                                        DataReader["citemcode"].ToString().Trim() + "')";

                                //MessageBox.Show(SQLCommand.CommandText);
                                Debug.WriteLine("\n" + SQLCommand.CommandText);
                                Debug.WriteLine(DataReader["clcc"].ToString().Trim());
                                Debug.WriteLine(DataReader["citemcode"].ToString().Trim());

                                SQLCommand.ExecuteNonQuery();

                                //Debug.WriteLine(dr["ID"].ToString());
                            }
                        }
                    }

                    DataConnection.Close();
                    SQLConnection.Close();
                }                          
            }
The program run with no error. But after it complete the running my database is still empty. I am wandering why the data are not inserted into my table.

please advise.

Signed By Ionix





Similar Threads
Thread Thread Starter Forum Replies Last Post
Regarding SqlCommand and.............. param99 SQL Server 2000 1 September 19th, 2006 07:29 AM
Regarding SqlCommand and.............. param99 SQL Language 0 September 19th, 2006 07:23 AM
SqlCommand & DataSet melvik ADO.NET 4 April 5th, 2004 11:50 AM
Problems with Sqlcommand.Connection.Open() leion General .NET 4 March 18th, 2004 12:41 AM





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