Pls do help me, I got an error Input String was not in a correct format.

Here is the code where error appears,

This is in my Record form.
After I click edit, it will be redirected to my Update2 form

Update2 f2 = new Update2();
                f2.BlockNo1 = Convert.ToInt32(BlockNo1);//error here
                f2.Firstname = Firstname;
                f2.Familyname = Familyname;
                f2.Dateofbirth = Dateofbirth;
                f2.Age = Age;
                f2.Bloodtype = Bloodtype;
                f2.Placeofbirth = Placeofbirth;
                f2.Religion = Religion;
                f2.Startofoccupancy = Startofoccupancy;
                f2.Contactnumber = Contactnumber;
                f2.NumberofChildren = NumberofChildren;
                f2.Numberofdogs = Numberofdogs;
                f2.Vaccinatedwithantirabies = Vaccinatedwithantirabies;
                f2.id1 = BlocNum2;
                f2.Show();
                dataGridView2.Update();
            }

Pls help me, Thank you

BlockNo1 in my table Spouse is a Number.

Here are the code for my Update2 form.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace sad
{
    public partial class Update2 : Form
    {
        public string Firstname, Familyname, Dateofbirth, Age, Bloodtype, Placeofbirth, Religion, Startofoccupancy, Contactnumber, NumberofChildren, Numberofdogs, Vaccinatedwithantirabies;
        public int id1, BlockNo1;
        public Update2()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OleDbCommand SQLCommand = new OleDbCommand();

           try
            {
                Records f1 = new Records();
                BlockNo1 = Convert.ToInt32(textBox11.Text);
                Firstname=textBox12.Text;
                Familyname = textBox13.Text;
                Dateofbirth = textBox14.Text;
                Age = textBox15.Text;
                Bloodtype = textBox16.Text;
                Placeofbirth = textBox17.Text;
                Religion = textBox18.Text;
                Startofoccupancy = textBox19.Text;
                Contactnumber = textBox20.Text;
                NumberofChildren = textBox21.Text;
                Numberofdogs = textBox22.Text;
                Vaccinatedwithantirabies = textBox23.Text;
                string SQLUpdateString;



                if (BlockNo1 == 0)
                {
                    SQLUpdateString = "UPDATE Personaldata SET BlockNo =" + BlockNo1.ToString() + ", Firstname='" + Firstname + "', Familyname='" + Familyname + "', Dateofbirth='" + Dateofbirth + "', Familyname='" + Familyname + "', Dateofbirth='" + Dateofbirth + "', Age='" + Age + "', Blooodtype='" + Bloodtype + "', Placeofbirth='" + Placeofbirth + "', Religion='" + Religion + "', Startofoccupancy='" + Startofoccupancy + "', Contactnumber='" + Contactnumber + "', NumberofChildren='" + NumberofChildren + "', Numberofdogs='" + Numberofdogs + "', Vaccinatedwithantirabies='" + Vaccinatedwithantirabies + "' WHERE BlockNo=" + BlockNo1 + "";

                }

                else
                {
                    SQLUpdateString = "UPDATE Personaldata SET BlockNo =" + BlockNo1.ToString() + ", Firstname='" + Firstname + "', Familyname='" + Familyname + "', Dateofbirth='" + Dateofbirth + "', Familyname='" + Familyname + "', Dateofbirth='" + Dateofbirth + "', Age='" + Age + "', Blooodtype='" + Bloodtype + "', Placeofbirth='" + Placeofbirth + "', Religion='" + Religion + "', Startofoccupancy='" + Startofoccupancy + "', Contactnumber='" + Contactnumber + "', NumberofChildren='" + NumberofChildren + "', Numberofdogs='" + Numberofdogs + "', Vaccinatedwithantirabies='" + Vaccinatedwithantirabies + "' WHERE BlockNo=" + BlockNo1 + "";


                }


                SQLCommand.CommandText = SQLUpdateString;
                SQLCommand.Connection = f1.database;
                SQLCommand.ExecuteNonQuery();






                MessageBox.Show("Update successful!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Hide();
                Records frm = new Records();
                frm.Show();
            }

           catch (Exception)
           {

           }
        }

        private void Update2_Load(object sender, EventArgs e)
        {
            textBox11.Text =""+BlockNo1;
            textBox12.Text = Firstname;
            textBox13.Text = Familyname;
            textBox14.Text =  Dateofbirth;
            textBox15.Text = Age;
            textBox16.Text =Bloodtype;
            textBox17.Text = Placeofbirth;
            textBox18.Text = Religion;
            textBox19.Text = Startofoccupancy;
            textBox20.Text = Contactnumber;
            textBox21.Text = NumberofChildren;
            textBox22.Text = Numberofdogs;
            textBox23.Text = Vaccinatedwithantirabies;
        }





    }
}

That error occurs if you have non-numeric data in the variable that you are trying to convert. Check to see what "BlockNo1" contains.

Which would have taken you 10 seconds to look up on MSDN instead of wasting everyones time posting here.

try this

f2.BlockNo1 = Convert.ToInt32(BlockNo1.ToString());
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.