hi guys ;

i have a code for read txt and later write to sql database but its not working :( can you help me _?

Best regards

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Data.SqlClient;
using Utilities;

namespace CDRImport
{
    public partial class Form1 : Form
    {
        public Form1()
        {
             InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
             string s = ReadFromFile(@"C:\Documents and Settings\Kaner\Desktop\CDR\01072009\ALTVER-BIR-QC-1_20090630 103600.dat");
             ParseCdr(s);
             //this.openFileDialog1.FileName = "*.xls";
             //openFileDialog1.ShowDialog();
        }

        static string ReadFromFile(string filename)
        {
             StreamReader sr;
             string s;
             sr = File.OpenText(filename);
             s = sr.ReadToEnd();
             sr.Close();
             sr.Dispose();
             return s;

        }

        private string[] ParseCdr(string s)
        {
             //1.31;16578;2;Altera-NXT;-1;-1;0;ALTVER-MEC-QC- 1;0;1;17;2;20090625;
             //114722;0;905053141819;05316004593;0;0;1;10;0;0 ;286015314308504;;
             //28601;0;;0;354183024362242;
             string [] sa = SplitByString(s, "\r\n");

             return sa;
        }
        //private void AddCDRs(string[] cdr)
        //{
        //    foreach (string s in cdr)
        //    {
        //        string[] cdrItems = s.Split(';');
        //        // loop cdr items


        //        // Execute SQL Command
                SqlCommand sqlCmd = new SqlCommand();
                DatabaseUtility.AddParameterToSqlCmd(sqlCmd, "@ReturnValue" , SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
                DatabaseUtility.AddParameterToSqlCmd(sqlCmd, "@gsm", SqlDbType.NVarChar, 10, ParameterDirection.Input, mustID);
                DatabaseUtility.AddParameterToSqlCmd(sqlCmd, "@ad", SqlDbType.NVarChar, 50, ParameterDirection.Input, sahip);
                DatabaseUtility.AddParameterToSqlCmd(sqlCmd, "@kk", SqlDbType.Int, 0, ParameterDirection.Input, kontor);
                DatabaseUtility.AddParameterToSqlCmd(sqlCmd, "@operator", SqlDbType.NVarChar, 20, ParameterDirection.Input, "VODAFONE");
                DatabaseUtility.AddParameterToSqlCmd(sqlCmd, "@optype", SqlDbType.Int, 0, ParameterDirection.Input, 3);
                DatabaseUtility.AddParameterToSqlCmd(sqlCmd, "@tarih", SqlDbType.DateTime, 0, ParameterDirection.Input, System.DateTime.Today);
                DatabaseUtility.SetCommandType(sqlCmd, CommandType.StoredProcedure, "Kontor_VeriEkle");
                DatabaseUtility.ExecuteScalarCmd(sqlCmd);
                return ((int)sqlCmd.Parameters["@ReturnValue"].Value);

        //    }

        //}


        private string[] SplitByString(string testString, string split)
        {
             int offset = 0;
             int index = 0;
             int[] offsets = new int[testString.Length + 1];

             while (index < testString.Length)
             {
                int indexOf = testString.IndexOf(split, index);
                if (indexOf != -1)
                {
                     offsets[offset++] = indexOf;
                     index = (indexOf + split.Length);
                }
                else
                {
                     index = testString.Length;
                }
             }

             string[] final = new string[offset + 1];
             if (offset == 0)
             {
                final[0] = testString;
             }
             else
             {
                offset--;
                final[0] = testString.Substring(0, offsets[0]);
                for (int i = 0; i < offset; i++)
                {
                     final[i + 1] = testString.Substring(offsets + split.Length, offsets[i + 1] - offsets - split.Length);
                }
                final[offset + 1] = testString.Substring(offsets[offset] + split.Length);
             }
             return final;
        }
    }
}

hi guys ;

i have a code for read txt and later write to sql database but its not working :( can you help me _?

When you need your car repair do you take it to a garage and tell the repairman "my car is broke, pleas fix it" ? Of course you don't -- you explain as well as you can what's wrong with it.

We are the same way. Don't just post a bunch of code and tell us "My code is broke". You have to tell us what is wrong with it, why do you think it doesn't do whatever its supposed to do. does it not compile? Then post some of the compile errors/warnings. Does it produce the wrong output? Then post the output.

commented: so true +3
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.