您好我是c#的新手我在组合框中遇到问题。
我希望用户从组合框中选择一个值并使用所选数据的值,在文本框中键入一些信息。
所有数据都应保存在另一个表格中。
组合框从国籍表填充,文本框包含员工信息。
应用程序使用sql server数据库,表单位于c#。
感谢
我提出的代码::::::::::
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);
}
}