I'm trying to read values from database into placeholder textbox but if one of the columns is null then throws the Unable to cast object of type 'System.DBNull' to type 'System.String'. And if I remove the textboxes that have null then I'm only seeing 1 ID even when it is two ID numbers in the database
SqlDataReader myReader = null;
SqlCommand command = new SqlCommand("sp_selectUser", objConnection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("@userNum", txtuserNum.Text);
myReader = command.ExecuteReader();
int i = 0;
while (myReader.Read())
{
TextBox txt = new TextBox();
txt.Text = (string)myReader["ID1"];
txt.Text = (string)myReader["ID2"];
txt.Text = (string)myReader["ID3"];
ContentPlaceHolder1.Controls.Add(txt);
ContentPlaceHolder1.Controls.Add(new
LiteralControl(" "));
ControlCache.Add(txt);
}