how to choose a value from combobox and insert it into record in c#

Hello I'm new at c# And I Have a problem in the combo box .

I want the user to select a value from the combo box and using the value of the selected data, type some information in text boxes.

All the data should be saved in another table.

The combo box is populated from the Nationality table and the text boxes contain employees information .

The application uses sql server database and the forms are in c#.

Thanks
the code I came up with::::::::::

enter code here private void btnSave_Click(object sender, EventArgs e)

 {
        try
        {
            ExPForm();
       string strConnectionString = @"Data Source = C:SQLEXPRESS; Integrated Security = SSPI; Initial Catalog = DB_Admin";
            SqlConnection con = new SqlConnection(strConnectionString);
            con.Open();
            string strExpCode = txtExpCode.Text.Trim();
            DateTime dtExpDate = dtPickerExpDate.Value;
            string strExpEmp = txtExpEmp.Text.Trim();
            string strExpGov = comboExpGov.SelectedItem.ToString();
        string strExpSubTitle = txtExpSubTitle.Text.Trim();
            string strExpSubSum = richtxtExpSubSum.Text.Trim();
             string strExpSubNote = txtExpSubNote.Text.Trim();
            string query = "INSERT INTO ExpTbl(ExpCode, ExpDate, ExpEmpName, GovID, OutInID,SubTypeID, LocID, ExpSubTitle, ExpSubSum, ExpSubNote)VALUES(@ExpCode, @ExpDate, @ExpEmpName, @GovID, OutInID,SubTypeID, LocID, @ExpSubTitle, @ExpSubSum, @ExpSubNote)";
            SqlCommand InsertCommand = new SqlCommand(query, con);
            InsertCommand.Connection = con;
            InsertCommand.Parameters.AddWithValue(@"strExpCode ", strExpCode);
            InsertCommand.Parameters.AddWithValue(@"strExpDate ", strDate);
            InsertCommand.Parameters.AddWithValue(@"GovID", GovID);
            InsertCommand.Parameters.AddWithValue(@"strOutInID",2);
            InsertCommand.Parameters.AddWithValue(@"SubTypeID", 2);
            InsertCommand.Parameters.AddWithValue(@"LocID", 2);
        InsertCommand.Parameters.AddWithValue(@"strExpSubTitle ", strExpSubTitle);
        InsertCommand.Parameters.AddWithValue(@"strExpSubSum ", strExpSubSum);
        InsertCommand.Parameters.AddWithValue(@"strExpSubNote ", strExpSubNote);           
 InsertCommand.ExecuteNonQuery();
            MessageBox.Show("New record has been added successfully");
            con.Close();
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }
链接地址: http://www.djcxy.com/p/68600.html

上一篇: 组合框事件触发了更改

下一篇: 如何从组合框中选择一个值并将其插入到c#中的记录中