User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 423,347 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 5,214 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 1213 | Replies: 16 | Solved
Reply
Join Date: Oct 2006
Location: India
Posts: 125
Reputation: bala24 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 11
bala24's Avatar
bala24 bala24 is offline Offline
Junior Poster

Re: create sqldatasource through coding

  #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  
Join Date: Feb 2008
Posts: 68
Reputation: johnny.g is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
johnny.g johnny.g is offline Offline
Junior Poster in Training

Re: create sqldatasource through coding

  #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  
Join Date: Feb 2008
Posts: 68
Reputation: johnny.g is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
johnny.g johnny.g is offline Offline
Junior Poster in Training

Re: create sqldatasource through coding

  #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
Dim conn = New SqlConnection("Data Source=(local);Initial Catalog=(databasename);user id=;pwd=;Trusted_Connection=yes")
        conn.open()
        Dim dr As SqlDataReader
        Dim cmd = New SqlCommand("select * from details", conn)
        dr = cmd.ExecuteReader()
        DropDownList1.DataSource = dr
        DropDownList1.DataTextField = "fname"
        DropDownList1.DataValueField = "srno"
        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
 DropDownList1.DataSource = dr
i dont want to use datasource at all,is it possible,,,,reply asasp
Johnny.G
Reply With Quote  
Join Date: Oct 2006
Location: India
Posts: 125
Reputation: bala24 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 11
bala24's Avatar
bala24 bala24 is offline Offline
Junior Poster

Re: create sqldatasource through coding

  #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 7:05 am.
Michelangelo

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

Re: create sqldatasource through coding

  #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  
Join Date: Oct 2006
Location: India
Posts: 125
Reputation: bala24 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 11
bala24's Avatar
bala24 bala24 is offline Offline
Junior Poster

Re: create sqldatasource through coding

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

Dim li As ListItem

If rd.HasRows Then
Do While rd.Read
	
        li = New ListItem
        li.Text= rd.Item("fname")
        li.Value = rd.Item("srid")
        <dropdownlist>.Items.Add(li)
Loop

rd.close()

End If
Last edited by bala24 : Jun 26th, 2008 at 7:39 am.
Michelangelo

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

Re: create sqldatasource through coding

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

Dim li As ListItem

If rd.HasRows Then
Do While rd.Read
	
        li = New ListItem
        li.Text= rd.Item("fname")
        li.Value = rd.Item("srid")
        <dropdownlist>.Items.Add(li)
Loop

rd.close()

End If

mind blowing maaannnnn,,,,,solved,,,thnks,,,hav added to ur reputation,,
thnks 1ce again
Johnny.G
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb ASP.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the ASP.NET Forum

All times are GMT -4. The time now is 11:51 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC