TextBox7.Text = pres1; TextBox8.Text = pList1.SelectedItem.Value.Trim();
SqlCommand distpostSqlCommand1 = new SqlCommand("Procedure1", linpostConnection); distpostSqlCommand1.CommandType = CommandType.StoredProcedure;
SqlParameter postParameter1 = new SqlParameter ("@Ime1", SqlDbType.NVarChar, 60); postParameter1.Direction = ParameterDirection.Input; postParameter1.Value = pres1; distpostSqlCommand1.Parameters.Add(postParameter1); SqlParameter postParameter2 = new SqlParameter ("@Ime2", SqlDbType.NVarChar, 60); postParameter2.Direction = ParameterDirection.Input; postParameter2.Value = pList1.SelectedItem.Value.Trim(); distpostSqlCommand1.Parameters.Add(postParameter2);
linpostConnection.Open();
SqlDataReader distSqlDataReader; distSqlDataReader = distpostSqlCommand1.ExecuteReader();
while (distSqlDataReader.Read()) { //if (distSqlDataReader[1] != DBNull.Value) //{ Int32 pomalor = Convert.ToInt32(distSqlDataReader[1]);
in the last line I got the error "Object can not be cast from DBNull.
Here is what I get as a result from the stored procedure in SQL;
I have two columns:
Ime1 Distance in m Mc Donalds 1980.19712674283
I can not understand from where I get this DBNull when viewing the site in web browser. Can anybody help me please?
Thank you very much in advance.