Click here to Skip to main content
13,141,068 members (56,270 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
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 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 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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web04 | 2.8.170915.1 | Last Updated 25 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100