score:5
Accepted answer
sqlCon = new SqlConnection(@"Data Source=PC-PC\PC;Initial Catalog=Anbar;Integrated Security=True");
SqlDataAdapter da = new SqlDataAdapter("Select StudentName from School", sqlCon);
DataTable dt = new DataTable();
da.Fill(dt);
yourComboBox.DataSource = dt;
yourComboBox.DisplayMember = "StudentName";
yourComboBox.ValueMember = "StudentName";
Also read this Populate Date from Database in a ComboBox
score:1
Use the following code
SqlDataAdapter da = new SqlDataAdapter("Select StudentName from School", sqlCon);
DataTable dat = new DataTable();
da.Fill(dat);
cmb.DataSource = dat;
cmb.DisplayMember = "StudentName";
cmb.ValueMember = "StudentName";
More questions
- combobox value in c sharp
- Remove duplication item from combobox auto added value from SQL Server
- How can I show the combobox selected value in a text box C#?
- How to check text of combobox with database column's value
- Assign value member from database to combobox
- Combobox doesn't show display member and value member in C#
- Adding hidden value of a column in SQL Server using C# in combobox
- replace comboBox value into number when inserted into sql
- Show DateTime value in combobox without time part (just "1/06/2016")
- Add a column with a default value to an existing table in SQL Server
- Cannot insert explicit value for identity column in table 'table' when IDENTITY_INSERT is set to OFF
- How to set a default value for an existing column
- Conversion of a datetime2 data type to a datetime data type results out-of-range value
- SQL Server - Return value after INSERT
- Add default value of datetime field in SQL Server to a timestamp
- Find a value anywhere in a database
- How do I set a column value to NULL in SQL Server Management Studio?
- How to Select Every Row Where Column Value is NOT Distinct
- Search all tables, all columns for a specific value SQL Server
- How to pass table value parameters to stored procedure from .net code
- How to split a comma-separated value to columns
- How can I query a value in SQL Server XML column
- How much size "Null" value takes in SQL Server
- How to select only the first rows for each unique value of a column?
- Is there a way to access the "previous row" value in a SELECT statement?
- Generate random int value from 3 to 6
- SQL - The conversion of a varchar data type to a datetime data type resulted in an out-of-range value
- What's the best way to select the minimum value from several columns?
- Multiple rows to one comma-separated value in Sql Server
- How can I fill a column with random numbers in SQL? I get the same value in every row
More questions with similar tag
- SQL Server equivalent of this MySQL sort clause
- User Authentication in ServiceStack
- Cons for using GROUP BY ALL?
- t-sql pivot - monthly revenue
- How to compute average time required to post a comment on stackexchange using SQL?
- Select & Update statement in stored procedure
- Sql Server Drop Database failure
- SQL queries - There are no primary or candidate > keys in the referenced table
- Missing Rows when running SELECT in SQL Server
- How to check a string is numeric using Regex in SQL Server?
- How do I Specify Computed Columns in a Table which are based on another Column in SQL Server?
- How to get the particular column value of the EXEC result in SQL?
- SQL Get the first occurance of the 15th for a date
- Migrating a SQL Server test database from development to test environment with a script?
- Master Data Services: Unauthorized
- SQL Server 2005 - Order of Inner Joins
- Python convert timedelta type to sql time type
- SQL (Microsoft) - 2 updates at same time
- SQL Server If Else If statement not working
- Recreating a For Loop in SQL Server?
- Raw SQL query in Entity Framework Core does not work properly when using string.Format
- SQL update one single row table with data from another
- Insert into replicated table fails - identity range check
- Explain SQL Query execution in this case
- Efficiently replacing many characters from a string
- insert select statement with certain columns only
- select rows from table based on data from another table
- SQL - Prepend a value if missing
- SQL Convert Week Number to Date (dd/MM)
- How to UNION sub-query in T-SQL
Source:
stackoverflow.com