How to retrieve data from database
-
I want to retrive data from SQL database using C#. and i want to put that data in DropDownList. How can i do this????? Please Help me. Thanks In advance.......!!
-
How about searching it in google ... This is for example : http://www.dotnetspider.com/resources/7644-Bind-DropDownList-from-DataBase-Using-c.aspx[^] If you don't want to use the datasource, then take the DataTable from dataSet.Tables[0] and read the data.
-
I want to retrive data from SQL database using C#. and i want to put that data in DropDownList. How can i do this????? Please Help me. Thanks In advance.......!!
I think this can help u u can use
SqlDataAdapter
andDataSet
classesSqlDataAdapter dd = new SqlDataAdapter(); DataSet de = new DataSet(); // For the Employees dd = new SqlDataAdapter("SELECT EmpName,isWaiter,isCashier FROM Employees", con);
//con is ur connection string to ur database
de.Clear();
try
{
con.Open();dd.Fill(de); int k; for (k = 0; k < de.Tables\[0\].Rows.Count; k++) { comboBox2.Items.Add(de.Tables\[0\].Rows\[k\].ItemArray\[0\].ToString()); } } catch(Exception ex) { MessageBox.Show(ex.Message.ToString()); }
-
How about searching it in google ... This is for example : http://www.dotnetspider.com/resources/7644-Bind-DropDownList-from-DataBase-Using-c.aspx[^] If you don't want to use the datasource, then take the DataTable from dataSet.Tables[0] and read the data.
-
I want to retrive data from SQL database using C#. and i want to put that data in DropDownList. How can i do this????? Please Help me. Thanks In advance.......!!
using System.Data;
using System.Data.SqlClient;Class test
{
public void pageload()
{SqlConnection conn = new SqlConnection(@"User id:sa; Password:password; Initial catalog: databaseName; data source:localhost"); conn.Open(); SqlCommand cmd = conn.CreateCommand(); cmd.CommandText = "SELECT bob FROM table"; SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { dropdownlist.Items.Add(reader\["bob"\].ToString()); } reader.Close(); conn.Close(); }
}