Reputation: 27
I encountered this problem where "Operand should contain 1 column(s)" when i want to insert data from other table and also add value from the textbox.
This is my code:
Try
MySQLCMD = New MySqlCommand
With MySQLCMD
.CommandText = "INSERT INTO attendance (stud_name, stud_id, sub_name, sub_prof, daytoday, time_in, remarks) VALUES ((SELECT stud_name, stud_id FROM temp_attendance), @sub_name, @sub_prof, @daytoday, @time_in, @remarks)"
.Connection = con
.Parameters.AddWithValue("@time_in", TextBoxTime2.Text)
.Parameters.AddWithValue("@sub_name", TextBoxSubjectName.Text)
.Parameters.AddWithValue("@sub_prof", TextBoxProfessor.Text)
.Parameters.AddWithValue("@daytoday", TextBoxDate.Text)
.Parameters.AddWithValue("@remarks", "Absent")
.ExecuteNonQuery()
End With
MsgBox("Data saved successfully", MsgBoxStyle.Information, "Information")
CallData()
ClearData()
Catch ex As Exception
MsgBox("Data failed to save !!!" & vbCr & ex.Message, MsgBoxStyle.Critical, "Error Message")
con.Close()
Return
End Try
Upvotes: 1
Views: 36
Reputation: 1256
Your CommandText should looks like this
CommandText = "INSERT INTO attendance (stud_name, stud_id, sub_name, sub_prof, daytoday, time_in, remarks) SELECT stud_name, stud_id , @sub_name, @sub_prof, @daytoday, @time_in, @remarks FROM temp_attendance"
Upvotes: 1