Click here to Skip to main content
15,895,011 members
Home / Discussions / C#
   

C#

 
QuestionDropDownList inside GridView Pin
msomar1-May-10 21:57
msomar1-May-10 21:57 
AnswerRe: DropDownList inside GridView Pin
Abhinav S1-May-10 22:42
Abhinav S1-May-10 22:42 
GeneralRe: DropDownList inside GridView Pin
Abdul-Rhman Alsri2-May-10 10:10
Abdul-Rhman Alsri2-May-10 10:10 
Questionmethod parameters error Pin
Abdul-Rhman Alsri1-May-10 17:00
Abdul-Rhman Alsri1-May-10 17:00 
AnswerRe: method parameters error Pin
Abhinav S1-May-10 17:15
Abhinav S1-May-10 17:15 
GeneralRe: method parameters error Pin
Abdul-Rhman Alsri1-May-10 18:43
Abdul-Rhman Alsri1-May-10 18:43 
AnswerRe: method parameters error Pin
Abhinav S1-May-10 20:34
Abhinav S1-May-10 20:34 
GeneralRe: method parameters error Pin
Pete O'Hanlon1-May-10 20:57
mvePete O'Hanlon1-May-10 20:57 
A slight correction to this code moves the line con1.Close before the return - it's unreachable code, but you could always set ExecuteReader with the parameter CommandBehavior.CloseConnection to shut the connection automatically. I'd also suggest wrapping the code in using blocks to trigger disposal of the objects.
using (SqlConnection con1 = new SqlConnection())
{
 con1.ConnectionString = ConfigurationManager.ConnectionStrings["Connectionstring"].ToString();
 string sql1 = "select " + colu + " from " + tbl + " where " + cond1 + " ='" + value1 + "' and " + cond2 + " = " + value2 + "";
 using (SqlCommand cmd1 = new SqlCommand(sql1, con1))
 {
  con1.Open();
  using (SqlDataReader dr = cmd1.ExecuteReader())
  {
   List<string> objList = new List<string>();
   while (dr.Read())
   {
    objList.Add(dr["ZoneCode"].ToString(););
   }
   return objList;
  }
 }
}

"WPF has many lovers. It's a veritable porn star!" - Josh Smith

As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.


My blog | My articles | MoXAML PowerToys | Onyx



GeneralRe: method parameters error Pin
Abhinav S1-May-10 21:19
Abhinav S1-May-10 21:19 
GeneralRe: method parameters error Pin
Pete O'Hanlon1-May-10 22:04
mvePete O'Hanlon1-May-10 22:04 
GeneralRe: method parameters error Pin
Abhinav S2-May-10 1:22
Abhinav S2-May-10 1:22 
GeneralRe: method parameters error Pin
Abdul-Rhman Alsri2-May-10 5:35
Abdul-Rhman Alsri2-May-10 5:35 
GeneralRe: method parameters error Pin
Pete O'Hanlon2-May-10 5:58
mvePete O'Hanlon2-May-10 5:58 
GeneralRe: method parameters error Pin
Abdul-Rhman Alsri2-May-10 6:15
Abdul-Rhman Alsri2-May-10 6:15 
GeneralRe: method parameters error Pin
Pete O'Hanlon2-May-10 7:16
mvePete O'Hanlon2-May-10 7:16 
GeneralRe: method parameters error Pin
Abdul-Rhman Alsri2-May-10 8:35
Abdul-Rhman Alsri2-May-10 8:35 
GeneralRe: method parameters error Pin
Pete O'Hanlon2-May-10 8:49
mvePete O'Hanlon2-May-10 8:49 
GeneralRe: method parameters error Pin
Abdul-Rhman Alsri2-May-10 9:59
Abdul-Rhman Alsri2-May-10 9:59 
GeneralRe: method parameters error Pin
Pete O'Hanlon2-May-10 10:12
mvePete O'Hanlon2-May-10 10:12 
Questionerror in insert 'msman88' Pin
Abdul-Rhman Alsri1-May-10 8:31
Abdul-Rhman Alsri1-May-10 8:31 
AnswerRe: error in insert 'msman88' Pin
Luc Pattyn1-May-10 8:36
sitebuilderLuc Pattyn1-May-10 8:36 
AnswerRe: error in insert 'msman88' Pin
Abhinav S1-May-10 8:36
Abhinav S1-May-10 8:36 
Questionhow to bring Graphic shapes to front of Form Pin
jojoba20111-May-10 4:05
jojoba20111-May-10 4:05 
AnswerRe: how to bring Graphic shapes to front of Form Pin
egenis1-May-10 4:46
egenis1-May-10 4:46 
AnswerRe: how to bring Graphic shapes to front of Form Pin
DaveyM691-May-10 10:26
professionalDaveyM691-May-10 10:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.