.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Bind combox, ListBox to SQL database column

Posted By:      Posted Date: October 04, 2010    Points: 0   Category :WPF

Hi everyone

  I am having problem where I want to bind a column of the database to the Combobox so that Item of the combobox are present in the database

for example I have a table named Animals which is in the following format

ID   Animal

1    Dog

2    Cat

3    Horse

4   Goat


So the Item of the Combobox are Dog, Cat, Horse and Goat.  I had tried to bind the database to ObservableCollection First and then bind that ObservableCollection to the combobox.

   public class NameList : List<PersonName>
	private LikesLINQDataContext newlikes = new LikesLINQDataContext();

	List<string> depart = new List<string>();

	 public NameList(): base()
		foreach (var lol in newlikes.Likes)

		foreach (stri

View Complete Post

More Related Resource Links

How to perform math on a column of data in SQL database and display it in my VB app

Sorry if this is the wrong forum, cos it's SQL and VB2010 So I have my sqlserver database 3.5 compact editon called "Dive Club Records" and in it are stored columns of dive trip information and I want tthe user to be able run a query from my VB2010 application to sum a divers total dive hours and display it on the form, eg: MemberID, FirstName, LastName, DiveTime by the way divetime is a real number recorded as 15.5, 20.5, 5.0 etc What is the easiest way to do this? Would prefere to do it from within VB2010 code if possible or make a query from the datagrid on my form using query designer. thanks for any suggestions from you all, hope you can keep them simple for me :)   regards   paul   paul

Write select query with a paremetrized where clause, and populate database with the retrieved column

I want to be able to retrieve column values using the dropdownlist values as parameters then populate the tbPO table with the retreived values. Where and how do I do it. ImportsSystem.Data.OleDb ImportsSystem ImportsSystem.IO Imports ?directcostDataSetTableAdapters PartialClass po_header  Inherits System.Web.UI.Page  Dim cn As OleDbConnection  Dim cmd As OleDbCommand  Dim dr As OleDbDataReader  Dim icount As Integer  Dim str As String  Dim vendor_id As Object   ?  Public Sub btn_click(ByVal sender As Object, ByVal e As System.EventArgs) Handles button1.ClickTry   context.Items.Add(     cmd.CommandType = System.Data.   cmd.CommandText = Dim context As HttpContext = HttpContext.Current"Company_Name", DropDownList3.Text)Dim cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Users\Owner\Documents\Visual Studio 2010\WebSites\WebSiteJun25\App_Data\directcost.mdb;")Dim cmd As New OleDbCommand()CommandType.Text"insert into tbPO(ponumber, suppliername, ShipTo, basictype, DateNeeded, Purpose,ShippingInstr, ProjId) values(?,?,?,?,?,?,?,?)" cmd.Parameters.AddWithValue( cmd.Parameters.AddWithValue( cmd.Parameters.AddWithValue( cmd.Parameters.AddWithValue( cmd.Parameters.AddWithValue( cmd.Parameters.AddWithValue( cmd.Parameters.AddWithValue( cmd.Parameters.Add

Select column from all tables in database

I want to retrieve the name and phone columns from all the tables in my database not in systables....   Ok this works but i dont want to get it from just the test table I want to get it from all the tables that I create "USE mrpoteat SELECT name, phone FROM mrpoteat.dbo.test where name = name and phone = phone"


the database result is as follows DATE     code   class1 class2  class3 1/8/10     M1     10       20     30     3/8/10     V2      20       30     10      1/8/10      H1      1           2      3         7/8/10     ! ! 8/8/10     !M2    5      5      5       3/8/10     B2      4      4     4       1/8/10     V1      3      7     3       THE OUTPUT SHOULD BE AS FOLLOWS:- DATE           M1                          M2           

Unable to Bind a CheckBox to an Oracle column

The code below works great in SQL Server with a BIT column.  How do you get it to work in Oracle?  I've tried number(1), char(1)...etc but nothing works!  Using Eval is no good becuse that breaks the Update. <asp:CheckBox ID="cbxStatus" runat="server" Checked='<%# Bind("status") %>' /> Always get this error: System.InvalidCastException: "Specified cast is not valid".  Anyone know the trick to making this work with Bind? 

How to Bind ListBox to ComboBox's SelectedItem

I have a ComboBox bound to a list of custom objects (Person). Each Person has a Friends collection. I want a ListBox below the ComboBox to contain a list of Friends depending on the Person selected in the ComboBox above it.   Something like: <ComboBox x:Name="MyComboBox" ItemsSource="{Binding People}"/> <ListBox ItemsSource="{Binding Element=MyComboBox, Path=SelectedItem.Friends}"/>   It doesn't work (null reference, I'm assuming because the SelectedItem.Friends is the wrong syntax.   Any pointers?

select only 3 digits from the database table column ?

hi all i want to select data from database like that i have a column name ID , i want to select only first three digits from that column ? how can i do it ?

how to set the computed column into inbuilt database into vs2008 ?

hi..i have designed a database into the vs 2008 mobile database.my batabase has three column column1(int),column2(int),column3(int) and i want to set the value of val(column3)=val(column1)+val(column2);how and where to set the computed column value.

What's the purpose of __sysP1 column in the client's database?

I have a SQL Server 2008 Publisher and SQL CE 3.5 subscriber and every so often the synchronization will fail giving me the error: A subscriber row failed to apply at the publisher. Review the error parameters and the conflict logging tables at the publisher to determine the reason the row failed to apply. [ Table name = <tableName>, Row guid = {F40FF701-4AF1-B011-92B1-CAE5B3335706} ] HRESULT 0x80004005 (28802) What I have found is that if I look at the record indicated above, the only difference from it and other records is that it has the value 0x01 for column __sysP1. I have looked for information on what that column means, but so far all I found is that it is a custom column. Any help will be greatly appreciated.

Finding underlying Eval or Bind column name from TemplateField

I need to be able to get the underlying column name from each TemplateField in my GridView. So I have something like:<asp:TemplateField HeaderText="Current Market Event" SortExpression="current_market_event"> <ItemTemplate> <asp:Label ID="Label2" runat="server" Text='<%# Eval("current_market_event") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> I see how to do this with a BoundField quiet easily: BoundField.DataField. Is there any way to do this for a TemplateField?

how to bind menu dynamically at runtime to database

Hi I'm new to ASP.Net. I need to bind data to menu navigation control from DataBase. These are the Tables I have...I know how to bind data from web.sitemap and xml, but not through database. If any changes are made in database, then automatically it should update in menu navigation control..plz guide me... Services --> E - Learning Education Software Products --> Education Individuals Corporate Customers --> Testimonials Careers --> Work Culture Current Openings About US --> Quality Policy Our Founder Our Team Thanks in Advance... even i can write code for it .but the main problem is that i dont know how i should create table structure .also navigate url column plz help

Bind listbox to gridview on client side



I have a list box (that uses a SQlDataSource) that has a list of jobs. I have a grid view (that also uses a SQLDataSource) that has the items used in each job. I want to bind the list box value to the gridview on the client side, i.e. when the user clicks on a different job in the list view I want the grid to show the items for that job.

Also, at formload I want the gridview to show the details of the first job on the listview.

Please let me know how I can do this in the aspx page.


- Sankaran

WPF: how can ListBox display three columns: first and thrid column width base on the longest content


We try to use ListBox to display three columns: so the first and last column width will depend on the longest content in that column to decide and second column take the rest of space as its width.

How can we use ListBox to achive that?

should we try with the ListView? thx!

How to Data bind to a listbox on a wpf usercontrol ?


Hi ,

what i have is a Windows form and in that form i have a elementhost which hosts a wpf usercontrol. On that control is a wpf listbox. In the windows form i have a routine that fetches data form the db.

How can i bind that data to the list box using the "{Binding = ???} attribute in the XAML ?

Currently i bubble up an event and on the event in the windows form i call an action whcih binds to the listbox. is that the correct way to do it



get database column datatype from metadata


Is there a way to get the database column DataType length information given a table's EntityType by sql query?


Example like: varchar(MAX), nvarchar(255),decimal(16, 4) .....


I need that query for documentation purpose.

Meng Chew

Unable to bind a List of a [DataContract] class to a ListBox




I have a class who is used by Silverlight though RIA Services and who contains the [DataContract] and on its properties [DataMember].

That class is also used by my WPF Application and i have a List<myClass> which i want to bind it on ListBox.


The problem is when i bind the list, when i select an item in my listbox, the first item is always selected and the right-click doesn't work properly.

In fact, the behavior of UI is weird and badly refreshed.

But, before, the class didn't have DataContract/DataMember attributes and it worked fine.


Do you know, a workaround to continue to use that class and avoid to create an other class specially for databind ?





Create a new Column in SQL-Database-GridView


Hi everybody,

at this time I try to  connect to a SQL-Database with ASP.net.

That works very well with DataGrid, but I want to add a new Column to the DataGrid with the number of the database rows.

The column have to be the first Column of DataGrid.

I want to create a function (with for-loop) to count the number of the row of a DataGrid and write it into DataGrid's first Column.

The number of Rows gets the DataGrid by the SQL-Database.

The SQL Database shouldn't get a new Column. I just want to create the column dynamically.

How could I realize this ? 


Here you can see my SourceCode:

Dim connStr As String = "server=WU900136\SQLEXPRESS; database=GT; Trusted_Connection=yes"
    Dim conn As New SqlConnection(connStr)

    Sub Page_Load(ByVal Sender As Object, ByVal E As EventArgs)
    End Sub
    Private Dataset As DataSet

    Sub rData()
        'Read Data
        Dim sql As String = "SELECT Bezeichnung Thema, starttermin Beginn, endtermin Ende From GR_Seminare, Gr_Termine WHERE Gr_Seminare.SemId=Gr_Termine.SemId"
        Dim cmd As New SqlCommand(sql, conn)
        Dim DataReader As SqlDataReader
        DataReader = cmd.E
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend