Guys I'm trying to insert data into a db and I'm using the following code:
String connectionString = "Provider=vfpoledb;Data Source=C:\\TESTE;Collating Sequence=machine;";
OleDbConnection FPDBConn = new OleDbConnection(connectionString);
FPDBConn.Open();
String strSQL = "INSERT INTO tercli ([id], [nome], [morada], [localidade], [codpostal], [telefone], [fax], [telemovel], [idcontr], [contribuin], [idzona], [zona], [idvendedor], [vendedor], [idpagament], [pagamento], [descontoge], [preco], [mapa], [dias], [plafond], [aviso], [email], [contacto], [rt_irs], [alim], [nru0], [cds0], [dtn0], [nru1], [nome1], [cds1], [dtn1], [nru2], [nome2], [cds2], [dtn2], [nru3], [nome3], [cds3], [dtn3], [nru4], [nome4], [cds4], [dtn4], [nru5], [nome5], [cds5], [dtn5], [dtini], [dtult], [dtprox], [obs], [agrup], [nbenef], [descontog1], [dtnasc], [activo], [cae], [resp], [ncontrato], [hst], [numexa], [numads], [numfunc], [cae1], [riva], [site], [datafac1], [datafac2], [bi], [carta], [sms], [mail], [prefer], [novo], [prof], [foto], [tel], [vlbi], [obs1], [prefer1], [distrito], [adesao], [sexo], [cpessoais], [nib], [balcao], [cproced], [dtfim], [pontostot], [pontosusa]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
OleDbCommand FPDBCmd = new OleDbCommand(strSQL, FPDBConn);
FPDBCmd.CommandType = CommandType.Text;
FPDBCmd.Parameters.AddWithValue("?", "5 ");
FPDBCmd.Parameters.AddWithValue("?", "Vitor");
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", "919042228");
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", 0.0000);
FPDBCmd.Parameters.AddWithValue("?", 0.0000);
FPDBCmd.Parameters.AddWithValue("?", "");
FPDBCmd.Parameters.AddWithValue("?", 0.000);
FPDBCmd.Parameters.AddWithValue("?", 0.0000);
FPDBCmd.Parameters.AddWithValue("?", "");
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", now);
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", now);
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", now);
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", now);
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", now);
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", now);
FPDBCmd.Parameters.AddWithValue("?", now);
FPDBCmd.Parameters.AddWithValue("?", now);
FPDBCmd.Parameters.AddWithValue("?", now);
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", 0.0000);
FPDBCmd.Parameters.AddWithValue("?", now);
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", 0.0000);
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", 0.0000);
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", 0.0000);
FPDBCmd.Parameters.AddWithValue("?", 0.0000);
FPDBCmd.Parameters.AddWithValue("?", 0.0000);
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", now);
FPDBCmd.Parameters.AddWithValue("?", now);
FPDBCmd.Parameters.AddWithValue("?", 0.0000);
FPDBCmd.Parameters.AddWithValue("?", 0.0000);
FPDBCmd.Parameters.AddWithValue("?", 0.0000);
FPDBCmd.Parameters.AddWithValue("?", 0.0000);
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", 0.0000);
FPDBCmd.Parameters.AddWithValue("?", now);
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", " ");
FPDBCmd.Parameters.AddWithValue("?", now);
FPDBCmd.Parameters.AddWithValue("?", 0.0000);
FPDBCmd.Parameters.AddWithValue("?", 0.0000);
FPDBCmd.ExecuteNonQuery();
FPDBCmd.Dispose();
FPDBConn.Close();
The thing is it seems to only be adding 1 parameter each time I run it instead of inputting all the parameters at the same time.
I've been looking at OleDbParameterCollection Class and doing OleDbParameter arrays but since the types of my parameters vary (OleDbType.Char, OleDbType.Numeric, OleDbType.DBDate and OleDbType.LongVarChar) I'm not exactly sure how to go about it...
Can you guys help, please?
Parametersacts like a dictionary where the names are keys. For OleDb the names don't matter for the mapping to the SQL, but do for keeping them separate.