我在3個表更新/插入數據
Clients: Client_ID, Client_Name, Client_Status,
Employees:Emp_ID, Emp_Name, Emp_Role
EmpJobs:EmpJob_ID, Emp_ID, Client_ID, Hours_Spent, Job_Date
現在我需要用戶在其中輸入數據(Hours_Spent,Job_Date)基於CLIENT_NAME和EMP_NAME EmpJobs的功能。這是我試過的
string constring = "Data Source=baker-pc;Initial Catalog=BakodahDB;Integrated Security=True";
string sqlQuery = (@"INSERT INTO EmpJobs (Hours_Spent, Job_Date)
values (@Hours_Spent,@Job_Date)
INNER JOIN Clients
ON EmpJobs.Client_ID=Clients.Client_ID
INNER JOIN Employees
ON EmpJobs.Emp_ID=Employees.Emp_ID
WHERE [email protected]_Name AND [email protected]_Name");
SqlConnection conDataBase = new SqlConnection(constring);
SqlCommand sqlCommand = new SqlCommand(sqlQuery, conDataBase);
conDataBase.Open();
sqlCommand.CommandText = sqlQuery;
sqlCommand.Parameters.Add("@Hours_Spent",SqlDbType.Int).Value = comboBox3.SelectedItem;
sqlCommand.Parameters.Add("@Job_Date",SqlDbType.Date).Value = Convert.ToDateTime(dateTimePicker1.Text);
sqlCommand.Parameters.Add("@Client_Name", SqlDbType.VarChar).Value = comboBox1.SelectedItem;
sqlCommand.Parameters.Add("@Emp_Name", SqlDbType.VarChar).Value = comboBox2.SelectedItem;
sqlCommand.ExecuteNonQuery();
conDataBase.Close();
MessageBox.Show("Saved!");
我在做什麼錯?什麼是正確的方法來做到這一點?
您面臨的困難是什麼? –
沒有條件插入,請嘗試更新 –
您是否遇到任何異常?數據只是不填充?正如@Am_I_Helpful所說,你遇到的實際問題是什麼? – gmiley