Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
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 24-Jan-13 21:51pm
Comments
K Gaurav Mishra at 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;

}
Rahul Dhoble at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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;
}
  Permalink  

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



Advertise | Privacy | Mobile
Web03 | 2.8.140709.1 | Last Updated 25 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid