Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
protected void DropDownListProject_SelectedIndexChanged1(object sender, EventArgs e)
       {
           if (DropDownListProject.SelectedIndex != 0)
           {
               string strTrans = string.Empty;
               SqlCommand cmd = new SqlCommand("select TransportAgency from project where proCode='" + DropDownListProject.SelectedValue.ToString() + "'", con);
               con.Open();
               strTrans = (string)cmd.ExecuteScalar();
               con.Close();
               txtTransport.Text = strTrans;
           }
       }
Posted
Comments
Gaurav K Mishra 25-Jan-13 4:53am    
Hi,
Write this code in try, Catch block and debug it line by line code change like
try
{
if (DropDownListProject.SelectedIndex != 0)
{
string strTrans = string.Empty;
string _Query="select TransportAgency from project where proCode='" + DropDownListProject.SelectedValue.ToString() + "'";

// Check _Query value copy that and run in Database App
SqlCommand cmd = new SqlCommand(_Query, con);
con.Open();
strTrans = (string)cmd.ExecuteScalar();
con.Close();
txtTransport.Text = strTrans;
}
}
catch(Exception ex)
{
lblMsg.ForeColor=System.Drawing.Color.Red;
lblMsg.Text="Error:"+ex.Message;

}
RDBurmon 25-Jan-13 5:23am    
Hi Gaurav , We will have to add this code in solution box so that OP could see and accept this as solution to his problem
I am adding it now . from now onwards please follow CP norms

1 solution

Hi, Write this code in try,
Catch block and debug it line by line code change like

C#
try { 
      if (DropDownListProject.SelectedIndex != 0)
        { 
          string strTrans = string.Empty; 
          string _Query="select TransportAgency from project where proCode='" + DropDownListProject.SelectedValue.ToString() + "'"; 
    
         // Check _Query value copy that and run in Database App 
         SqlCommand cmd = new SqlCommand(_Query, con); 
         con.Open(); 
         strTrans = (string)
         cmd.ExecuteScalar(); 
         con.Close(); 
         txtTransport.Text = strTrans;
        } 
      } 
catch(Exception ex) 

{ 
  lblMsg.ForeColor=System.Drawing.Color.Red; 
  lblMsg.Text="Error:"+ex.Message;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900