I am trying to insert from code behind on an asp.net form,
I have two tables:
Table Trainings
training_id
training_Date
.
.
Table personTraining
id
training_id
name,
dept
Am I doing something wrong?
I need to insert the values from the form , plus, select the values from a lookup table , where the training id is equal to dropdown selected value .
private void InsertInfo()
{
SqlConnection conn = new SqlConnection(GetConnectionString());
string sql = "INSERT INTO personTraining (name,training_id,training,trainingDate.trainingHour,trainingSession) VALUES (@Val1,SELECT (training_id,training,trainingDate.trainingHour,trainingSession FROM tbl_training WHERE training_id = dpDate.selectedValue))";
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.Parameters.AddWithValue("@Val1", txtName.Text);
//will add rest of form fields
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
You would need to use something like
You can’t have a hybrid
VALUESclause/SELECTstatement like that.