Link to home
Start Free TrialLog in
Avatar of searchsanjaysharma
searchsanjaysharma

asked on

How to correct this error and why it comes.

I have a windows form and coding in vb.net.
A textbox txttid is there.
When i enter any numbers if fetches the data based on that tid and returns the resultset.
If no data is available then it gives invalid TID as message
empties the txttid.But simultenously raises the following exception

The Query is :

s = "select isnull(sname,''),isnull(gender,''),isnull(slandline,''),isnull(smobile,''),isnull(sstate,'') from mststudents where id=" & Convert.ToInt32(TXTTID.Text.Trim()) & " and sname is  null"
            da = New SqlDataAdapter(s, con)
            dt = New DataTable
            da.Fill(dt)
            If dt.Rows.Count = 0 Then
                MessageBox.Show("Invalid TID")
                TXTTID.Text = ""
                TXTTID.Focus()
                txtuin.Text = ""
                txtuin.Enabled = False

            Else
                txtsname.Text = dt.Rows(0)(0).ToString()
            end if

Exception is System.Format  Exception. Input string was not in correct format.
Avatar of kaufmed
kaufmed
Flag of United States of America image

The reason you would get that error is if your call to Integer.ConvertToInt32 was passed a non-numeric string. Check that the data you are passing is correct--even a blank or empty string will raise this exception.

See #2 here:  https://www.experts-exchange.com/Programming/Languages/.NET/A_5389-5-Common-Exceptions-in-NET-and-How-to-Resolve-Them.html
ASKER CERTIFIED SOLUTION
Avatar of Arthur_Wood
Arthur_Wood
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of searchsanjaysharma
searchsanjaysharma

ASKER

ok