دوست من این کدیه که الان نوشتم ولی مسلما تنها راه نیست
private void btnfill_Click(object sender, EventArgs e)
{
try
{
SqlConnection sc = new SqlConnection(@"data source = MOYA-LAP\MOHAMMADSERVER ; database = test; user id = sa ; password = moyamoya");//@"data source = moya-pc\mohammadserver ; database =test;integrated security = true");
SqlCommand cmd = new SqlCommand("select name from student", sc);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable table = new DataTable();
sda.Fill(table);
foreach (DataRow dr in table.Rows)
{
cbox1.Items.Add(dr[0]);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}