نوشته شده توسط
ordebehesht
حالا چطور به بانک باین کنیم
خیلی راحت
public void getList()
{
// set the connectionstring for the database
SqlConnection con = new SqlConnection();
try
{
//before adding records in combobox clear previous data
cmbMemberName.Items.Clear();
// define the sql query that should we want to perform
con.ConnectionString = "Data Source=INDIA\\SQLEXPRESS;Initial Catalog=test;Integrated Security=True";
// define the sql query that should we want to perform
string query = "select member_id,member_name,member_email from Member_Master";
//create object of Sqlcommand class and pass two parameters sqlserver query and sqlconnection con
SqlCommand cmd = new SqlCommand(query, con);
//set the commandtext to query
cmd.CommandText = query;
//before perform sql operation open the connection
con.Open();
//execute the ExecuteReader
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
//add item by item in combobox
cmbMemberName.Items.Add(dr["member_id"].ToString() + " " + dr["member_name"].ToString() + " " + dr["member_email"].ToString());
}
}
catch
{
MessageBox.Show("Error in Connection");
}
//close the connection
con.Close();
}