Help Text File

Jun 26 2006 12:44 PM
Hi,
i have this text file

GENUARDI ADOLFO

90100

04800530828

VIA ORETO139

MARCHESE SALVATORE

90100

00464940824

IAZZA CARMINE 40

I must read 4 line each time  and put into a database so till the end of the document,
i wrote this code but is not right

try

{

StreamReader sr=new StreamReader("\\Program Files\\SIP\\clienti.txt");

string[] After;

ArrayList lines = new ArrayList();

string line;

int lineb=0;

int conta=0;

while ((line = sr.ReadLine()) != null)

lines.Add(line);

if(conta % 4==0)

{

string a = (string) lines[0];

string b = (string) lines[1];

string c = (string) lines[2];

string d = (string) lines[3];

SqlCeConnection cn = new SqlCeConnection("Data Source=\\Program Files\\SIP\\data.sdf");

cn.Open();

string gg="INSERT INTO clienti(nome,CAP,piva,Indirizzo) VALUES('"+a.ToString()+"','"+b.ToString()+"','"+c.ToString()+"','"+d.ToString()+"')";

SqlCeCommand cmd = new SqlCeCommand(gg,cn);

cmd.ExecuteNonQuery();

cn.Close();

cont++;

}

}

catch(SqlCeException ex)

{

MessageBox.Show("Errore"+ex.Message+ex.Errors);

}
Please help me Bye


Answers (2)