Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Force textbox Value to put in float data

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading