create sqldatasource through coding

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Oct 2006
Posts: 125
Reputation: bala24 is an unknown quantity at this point 
Solved Threads: 11
bala24's Avatar
bala24 bala24 is offline Offline
Junior Poster

Re: create sqldatasource through coding

 
0
  #11
Jun 26th, 2008
Well glad to help.
Do remember to set this thread as Solved so that others could benefit from this solution.
Michelangelo

"The best place to find a helping hand is at the end of your own arm"
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 85
Reputation: johnny.g is an unknown quantity at this point 
Solved Threads: 3
johnny.g johnny.g is offline Offline
Junior Poster in Training

Re: create sqldatasource through coding

 
0
  #12
Jun 26th, 2008
Originally Posted by bala24 View Post
Well glad to help.
Do remember to set this thread as Solved so that others could benefit from this solution.
,,yup hav done tht,,,thnks 1ce again
Johnny.G
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 85
Reputation: johnny.g is an unknown quantity at this point 
Solved Threads: 3
johnny.g johnny.g is offline Offline
Junior Poster in Training

Re: create sqldatasource through coding

 
0
  #13
Jun 26th, 2008
Originally Posted by johnny.g View Post
thnks dude ,,,will go thr tht link n let u know if it wrks for me,,,,
by the way i found a the code tht i wanted finally,,,here it is ,its very simple using only sql data reader,,,here it is
  1. Dim conn = New SqlConnection("Data Source=(local);Initial Catalog=(databasename);user id=;pwd=;Trusted_Connection=yes")
  2. conn.open()
  3. Dim dr As SqlDataReader
  4. Dim cmd = New SqlCommand("select * from details", conn)
  5. dr = cmd.ExecuteReader()
  6. DropDownList1.DataSource = dr
  7. DropDownList1.DataTextField = "fname"
  8. DropDownList1.DataValueField = "srno"
  9. DropDownList1.DataBind()
well this works for me,,thnks for all ur help
dude is there ne way we can get the result by editing the line
  1. DropDownList1.DataSource = dr
i dont want to use datasource at all,is it possible,,,,reply asasp
Johnny.G
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 125
Reputation: bala24 is an unknown quantity at this point 
Solved Threads: 11
bala24's Avatar
bala24 bala24 is offline Offline
Junior Poster

Re: create sqldatasource through coding

 
0
  #14
Jun 26th, 2008
Well one way is to loop through the datareader and get the values in each row and add it to dropdownlist.
This involves the following steps.

While end of datareader
create list item instance
add fname of row(i) to listitem text
add srid of row(i) to listitem value
add listitem to dropdownlist
end while
Last edited by bala24; Jun 26th, 2008 at 8:05 am.
Michelangelo

"The best place to find a helping hand is at the end of your own arm"
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 85
Reputation: johnny.g is an unknown quantity at this point 
Solved Threads: 3
johnny.g johnny.g is offline Offline
Junior Poster in Training

Re: create sqldatasource through coding

 
0
  #15
Jun 26th, 2008
Originally Posted by bala24 View Post
Well one way is to loop through the datareader and get the values in each row and add it to dropdownlist.
This involves the following steps.
well bala ,,it was a bouncer to me,,can u explain me with the exact code..
reply asap,,thnks in advance
Johnny.G
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 125
Reputation: bala24 is an unknown quantity at this point 
Solved Threads: 11
bala24's Avatar
bala24 bala24 is offline Offline
Junior Poster

Re: create sqldatasource through coding

 
1
  #16
Jun 26th, 2008
Do fill in the rest of the details

  1. Dim li As ListItem
  2.  
  3. If rd.HasRows Then
  4. Do While rd.Read
  5.  
  6. li = New ListItem
  7. li.Text= rd.Item("fname")
  8. li.Value = rd.Item("srid")
  9. <dropdownlist>.Items.Add(li)
  10. Loop
  11.  
  12. rd.close()
  13.  
  14. End If
Last edited by bala24; Jun 26th, 2008 at 8:39 am.
Michelangelo

"The best place to find a helping hand is at the end of your own arm"
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 85
Reputation: johnny.g is an unknown quantity at this point 
Solved Threads: 3
johnny.g johnny.g is offline Offline
Junior Poster in Training

Re: create sqldatasource through coding

 
0
  #17
Jun 26th, 2008
Originally Posted by bala24 View Post
Do fill in the rest of the details

  1. Dim li As ListItem
  2.  
  3. If rd.HasRows Then
  4. Do While rd.Read
  5.  
  6. li = New ListItem
  7. li.Text= rd.Item("fname")
  8. li.Value = rd.Item("srid")
  9. <dropdownlist>.Items.Add(li)
  10. Loop
  11.  
  12. rd.close()
  13.  
  14. End If
mind blowing maaannnnn,,,,,solved,,,thnks,,,hav added to ur reputation,,
thnks 1ce again
Johnny.G
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 1
Reputation: jpramac is an unknown quantity at this point 
Solved Threads: 0
jpramac jpramac is offline Offline
Newbie Poster

Re: create sqldatasource through coding

 
0
  #18
Nov 11th, 2008
Originally Posted by serkansendur View Post
  1. protected void Page_Load(object sender, EventArgs e)
  2. {
  3. if (!IsPostBack)
  4. {
  5. SqlDataSource mySource = new SqlDataSource("Data Source=SERKAN\\MYSQLSERVER2005;Initial Catalog=deneme;Integrated Security=True;Pooling=False", "select * from names");
  6. myDropDown.DataSource = mySource.Select(DataSourceSelectArguments.Empty);
  7. myDropDown.DataValueField = "PKID";
  8. myDropDown.DataTextField = "name";
  9. myDropDown.DataBind();
  10. }
  11. }

This is a great sample. I've been searching google for an hour to find a good sample for creating a sqldatasource in a class. Thank you!!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC