| | |
create sqldatasource through coding
Please support our ASP.NET advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Feb 2008
Posts: 85
Reputation:
Solved Threads: 3
hi all i m using asp.net 2005 and sql server 2005...i have a dropdown list in my page...i have a table called as details...all i want to do is bind the fname from details table to dropdownlistbox...but the thing is tht i want to each and every step through coding...is it possible to do so....pls let me know how to do it,,,,,,,frm whr do i strt ...
thnks in advance
thnks in advance
Johnny.G
•
•
Join Date: Jan 2008
Posts: 2,052
Reputation:
Solved Threads: 123
ASP.NET Syntax (Toggle Plain Text)
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { SqlDataSource mySource = new SqlDataSource("Data Source=SERKAN\\MYSQLSERVER2005;Initial Catalog=deneme;Integrated Security=True;Pooling=False", "select * from names"); myDropDown.DataSource = mySource.Select(DataSourceSelectArguments.Empty); myDropDown.DataValueField = "PKID"; myDropDown.DataTextField = "name"; myDropDown.DataBind(); } }
Due to lack of freedom of speech, i no longer post on this website.
•
•
Join Date: Feb 2008
Posts: 85
Reputation:
Solved Threads: 3
•
•
•
•
ASP.NET Syntax (Toggle Plain Text)
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { SqlDataSource mySource = new SqlDataSource("Data Source=SERKAN\\MYSQLSERVER2005;Initial Catalog=deneme;Integrated Security=True;Pooling=False", "select * from names"); myDropDown.DataSource = mySource.Select(DataSourceSelectArguments.Empty); myDropDown.DataValueField = "PKID"; myDropDown.DataTextField = "name"; myDropDown.DataBind(); } }
Johnny.G
Yes you can. Follow these steps.
1).Create a query which fetches the fname from details table.
2).Call cmd.ExecuteReader with this query.
3).Now bind the dropdownlist from the datareade.
For this step you can use the following code.
1).Create a query which fetches the fname from details table.
2).Call cmd.ExecuteReader with this query.
3).Now bind the dropdownlist from the datareade.
For this step you can use the following code.
•
•
•
•
<dropdownlist>.DataSource = <datareader>
<dropdownlist>.DataBind()
Michelangelo
"The best place to find a helping hand is at the end of your own arm"
"The best place to find a helping hand is at the end of your own arm"
•
•
Join Date: Feb 2008
Posts: 85
Reputation:
Solved Threads: 3
•
•
•
•
Yes you can. Follow these steps.
1).Create a query which fetches the fname from details table.
2).Call cmd.ExecuteReader with this query.
3).Now bind the dropdownlist from the datareade.
For this step you can use the following code.
here is my code
If Not Page.IsPostBack Then
Dim conn As SqlConnection
Dim cmd As SqlCommand
Dim dr As SqlDataReader
Dim str1 As String
Dim strcon As String
str1 = "select * from details"
strcon = "Data Source=PC-1;Initial Catalog=jay;user id=;pwd=;Trusted_Connection=yes"
conn = New SqlConnection(strcon)
conn.Open()
cmd = New SqlCommand(str1, conn)
dr = cmd.ExecuteReader()
DropDownList1.DataSource = dr
DropDownList1.DataValueField = "srno"
DropDownList1.DataTextField = "fname"
DropDownList1.DataBind()
______________________________________
it gives an error...any suggestions,,i have written ths code on page load,,,reply asap
Johnny.G
•
•
Join Date: Feb 2008
Posts: 85
Reputation:
Solved Threads: 3
•
•
•
•
Well, your sql query is fetching all columns from the table and your dropdownlist cannot be bound to such a recordset.
What you need to do is modify your sql query to fetch only fname as in
select fname from details
ASP.NET Syntax (Toggle Plain Text)
dbconn.Open() If Not Page.IsPostBack Then dbadap = New SqlDataAdapter("select fname from details", dbconn) dbadap.Fill(ds, "details") DropDownList1.DataSource = ds.Tables("details").DefaultView DropDownList1.DataBind() DropDownList1.SelectedValue = "" MsgBox(DropDownList1.SelectedValue) DropDownList1.DataValueField = "srno" DropDownList1.DataTextField = "fname" End If
well in this code,,the dropdown list gets filled with system.data.datarowview
i want tht to fill with fname...reply asap
Johnny.G
•
•
Join Date: Feb 2008
Posts: 85
Reputation:
Solved Threads: 3
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
well this works for me,,thnks for all ur help
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
ASP.NET Syntax (Toggle Plain Text)
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()
Johnny.G
![]() |
Other Threads in the ASP.NET Forum
- Previous Thread: Load image in report in runtime in ASP.Net
- Next Thread: ASP.net - Flash Postback problem : Please Help
Views: 3866 | Replies: 17
| Thread Tools | Search this Thread |
Tag cloud for ASP.NET
.net 2.0 activexcontrol advice ajax alltypeofvideos anathor application asp asp.net bc30451 bottomasp.net box browser button c# checkbox commonfunctions complex connection dataaccesslayer database datagridview datagridviewcheckbox datalist development dgv dropdownlist dynamically edit editing expose feedback fileuploader fill flash form formatdecimal formview google gridview gudi iframe iis javascript list listbox login microsoft migration mono mouse mssql news numerical opera panelmasterpagebuttoncontrols parent problem project radio redirect registration relationaldatabases reportemail richtextbox rows save schoolproject search security select services session silverlight smartcard smoobjects software sql sql-server sqlserver2005 suse textbox theft tracking unauthorized validation vb.net video videos view vista visualstudio web webapplications webdevelopemnt webprogramming webservice xsl youareanotmemberofthedebuggerusers






