This is a part of my code:
private void button2_Click(object sender, EventArgs e)
{
try
{
string NumSaisie = textNumSaisie.Text;
DateTime Jour = DateTime.Parse(txtDate.Text);
string NumCpt = txtNdC.Text;
string Lib = txtLib.Text;
string Descri = txtDescri.Text;
float Debit = txtDebit.Text;
float Credit = txtCredit.Text;
con.Open();
OleDbCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = " INSERT INTO Saisie2 VALUES ('" + NumSaisie + "', '"+ Jour + "', '"+ NumCpt + "', '"+ Lib + "', '"+ Descri + "', '"+ Debit + "', '"+ Credit + "')";
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("ok");
}
catch (Exception)
{
throw;
}
I’m trying to put data in an Access document for my personnel accounting; however, I have some difficulties about incompatibilities of data. My idea with the variables id to force textbox values to be in a good format so they will be accepted by Access.
I see in my error that we cannot put a text value in float value, so I a, searching in each value after the dot to see which one will be good to use (to replace .Text), however I haven’t any idea of which one.
>Solution :
If you know that the text is only the number and nothing else, you could use float.Parse(txtDebit.Text) to convert from string to float.