Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

The value from the dropdownlist doesn't appear in the textbox C#

$
0
0

Hi,

I have a dropDownList in my web form and I on selecting a certain value from the dropdownlist I want the values from the database for that value to apper in the textboxes.

I have this code:

 String name = incDropDownList.SelectedItem.Value.Trim();
            SqlCommand incSqlCommand =
                    new SqlCommand("listIncidents", conn);
            incSqlCommand.CommandType = CommandType.StoredProcedure;
            SqlParameter incParameter = new SqlParameter
                ("@nameInc", SqlDbType.NVarChar, 60);
            incParameter.Direction = ParameterDirection.Input;
            incParameter.Value = name;
            incSqlCommand.Parameters.Add(incParameter);

            SqlDataReader incSqlDataReader;
            try
            {
                conn.Open();
                incSqlDataReader = incSqlCommand.ExecuteReader();

                while (incSqlDataReader.Read())
                {
                    txtName.Text = incSqlDataReader[0].ToString();                    
                    txtLattitude.Text = Convert.ToString(incSqlDataReader[2]);
                    txtLongitude.Text = Convert.ToString(incSqlDataReader[1]);
                }

                incSqlDataReader.Close();
            }
            catch (SqlException exc)
            {
                Response.Write(exc.ToString());
            }
            catch (Exception ex)
            {
                Response.Write(ex.ToString());
            }
            finally
            {
                conn.Close();
            }

but the values in the textboxes doesn't appear.

Can anybody help me please where I go wrong?

Thanks


Viewing all articles
Browse latest Browse all 31927

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>