<configuration> <appSettings> <add key="ConnectionString" value="Server=NAMIT-KB\SQLEXPRESS;Database=Interview_UNM_DB;UserID=sa;Pwd=manager"/> </appSettings> </configuration>
using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; using System.IO; using System.Configuration; namespace Window_MyShop_2110 { public partial class frmHome : Form { //string strConn = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; //DataTable tmp; //SqlDataAdapter dA; //string strData = string.Empty; public frmHome() { InitializeComponent(); } private void frmHome_Load(object sender, EventArgs e) { SqlConnection con = new SqlConnection(@"Server=NAMIT-KB\SQLEXPRESS;Database=Interview_UNM_DB;UserID=sa;Pwd=manager"); //SqlCommand cmd = new SqlCommand("Select * from table_CreateFirm Where Category='Cloth'",strConn); SqlCommand cmd = new SqlCommand(); cmd.Connection = con; cmd.CommandType = CommandType.Text; cmd.CommandText = "Select * from table_CreateFirm Where Category='Cloth"; DataSet objDs = new DataSet(); SqlDataAdapter dAdapter = new SqlDataAdapter(); dAdapter.SelectCommand = cmd; con.Open(); dAdapter.Fill(objDs); con.Close(); cBoxFirmName.ValueMember = "FirmID"; cBoxFirmName.DisplayMember = "FirmName"; cBoxFirmName.DataSource = objDs.Tables[0]; } }
Quote:comboBox2.Items.Clear(); SqlConnection con=new SqlConnection("Data Source=.; Initial Catalog=Dbname;uid=sa;pwd=password"); try { con.Open(); SqlCommand cmd = new SqlCommand("select distinct(Name) from Addgodown order by name asc", con); dr = cmd.ExecuteReader(); while (dr.Read()) { comboBox2.Items.Add(dr[0].ToString()); } dr.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { con.Close(); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)