Hello,
I once thought that I solved this problem, but I got it again, and I don't know what is the problem.
When I put only
pom = distpostSqlCommand1.ExecuteScalar()
TextBox4.Text = pom.ToString();
I get correct value in my textbox but when I try to convert it in Int32, since I need it to compare with a minimum value and use
Int32 rast = Convert.ToInt32(pom);
I get an error:
Exception Details: System.InvalidCastException: Object cannot be cast from DBNull to other types.
Source Error:
Line 119: TextBox4.Text = pom.ToString();
Line 120: Int32 rast = Convert.ToInt32(pom);
Sam HobbsPosted May 4, 2011, 4:13 PM
NelPosted May 5, 2011, 3:17 AM
May I ask you one more question please?
Is it good to work with embedded SQLDataReaders, or not? I have a while loop where I find elements with the help of stored procedure. So I am wondering whether it is better to make it as a string of elements and put a counter inside the while loop, close the loop and start another one for finding the min distance, or I can insert another dataReader inside the first while loop for the first DataReader and chack which of the elements is with min. distance, using the second stored procedure.
Thank you very much in advance.
Sam HobbsPosted May 5, 2011, 2:03 AM
NelPosted May 5, 2011, 1:36 AM
Thanks again.
NelPosted May 4, 2011, 11:19 AM
Guest UserPosted May 4, 2011, 11:04 AM
TextBox4.Text = pom.ToString();
Then this should work too:
Int32 rast = Convert.ToInt32(pom.ToString());
NelPosted May 4, 2011, 8:52 AM
If I put a check whether it is null, it behaves as if it was, but in the text box if I don't use the conversion when pomalor object is shown in the textbox it is a correct value
Ankit NandekarPosted May 4, 2011, 8:30 AM
Jiteendra SampathiraoPosted May 4, 2011, 8:04 AM
you must check if it is equal to DBNull first because DBNull does not equal "null".
check the condition before assigning the value.
if ( XXXXX != System.DBNull.Value)
{
}
Vijay YadavPosted May 4, 2011, 8:02 AM
can please tell what is pom here?
or else you can directly convert the
TextBox4.Text = convert.ToInt32(distpostSqlCommand1.ExecuteScalar()) and i would suggest before doing this just check whether the executescalar is null or not.