kopiowanie tekstu do bazy danych accessa

0

witam,

mam takie zadanie: napisac program, ktory z pliku .txt kopiuje linie i wkleja je w kolumne w tabeli bazy danych access.
mam taki problem: Element OleDbParameterCollection akceptuje tylko obiekty niezerowe typu OleDbParameter, a nie obiekty String.

caly komunikat: "Error: Failed to insert the required data to the DataBase.
Element OleDbParameterCollection akceptuje tylko obiekty niezerowe typu OleDbParameter, a nie obiekty String.
Hit enter to continue."

ponizej kod:

 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Collections;
using System.Data;
using System.Data.OleDb;
using System.Xml.Serialization;

namespace TekstDoAccess
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] allLines = File.ReadAllLines("input.txt");
            string strAccessConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=output.MDB";

            string strCommandTextCreate = "CREATE TABLE TestTable (pierwsza decimal (4,2))";
            string strCommandTextInsert = "INSERT INTO TestTable VALUES (@pierwsza)";

            // Create the dataset and add the Categories table to it:
            //DataSet myDataSet = new DataSet();
            OleDbConnection myAccessConn = null;
            try
            {
                myAccessConn = new OleDbConnection(strAccessConn);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: Failed to create a database connection. \n{0}", ex.Message);
                return;
            }

            try
            {
                OleDbCommand myAccessCommandFirst = new OleDbCommand(strCommandTextCreate, myAccessConn);
                OleDbCommand myAccessCommandSecond = new OleDbCommand(strCommandTextInsert, myAccessConn);
                
                OleDbDataAdapter myDataAdapterA = new OleDbDataAdapter(myAccessCommandFirst);
                OleDbDataAdapter myDataAdapterB = new OleDbDataAdapter(myAccessCommandSecond);

                myAccessConn.Open();
                myAccessCommandFirst.ExecuteNonQuery();
                
                myAccessCommandSecond.Parameters.Add("@pierwsza");
                //myAccessCommandSecond.CommandType
                for (int i = 1; i < allLines.Length; i++)
                {
                    /*string[] items = allLines[i].Split(new char[] { ' ' });
                    myAccessCommandSecond.Parameters["@pierwsza"].Value = items[0];*/
                    /*OleDbParameter op = new OleDbParameter("OP", OleDbType.VarChar, 100);
                    op.Value = allLines[i];
                    myAccessCommandSecond.Parameters.Add(op);*/
                    myAccessCommandSecond.Parameters["@pierwsza"].Value = allLines[i];
                    myAccessCommandSecond.ExecuteNonQuery();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: Failed to insert the required data to the DataBase.\n{0}", ex.Message);
                return;
            }
            finally
            {
                myAccessConn.Close();
                Console.WriteLine("Hit enter to continue.");
                Console.ReadKey();
            }           
        }
    }
}

Prosze o pomoc.

0

nadal nie znalazłem rozwiązania

1 użytkowników online, w tym zalogowanych: 0, gości: 1