public Form1()
{
DateTime dt = DateTime.Now;
DataTable DTable = new DataTable();
SqlDataAdapter DAdapter;
SqlConnection myConnection;
SqlCommand myCommand;
InitializeComponent();
myConnection = new SqlConnection("Server=Server;Trusted_Connection=yes;DataBase=Bar");
myCommand = new SqlCommand("SELECT КодСотрудника,Фамилия,Имя FROM Сотрудники ORDER BY Фамилия", myConnection);
try
{
DAdapter = new SqlDataAdapter(myCommand);
DAdapter.Fill(DTable);
}
catch (Exception ee)
{
Console.WriteLine(ee.ToString());
}
textBox1.DataBindings.Add("Text", DTable, "Имя");
comboBox1.DataSource = DTable;
comboBox1.ValueMember = "КодСотрудника";
comboBox1.DisplayMember = "Фамилия";
}
private void comboBox1_SelectedValueChanged(object sender, EventArgs e)
{
string str = comboBox1.SelectedValue.ToString();
textBox1.Text = str; // Ok!
int number = Convert.ToInt32(str); // Error!
}}