0

I want to Delete data from two gridviews(Using Foreign Key) when i click a button!..This is What I've tried and gives me an error "Incorrect Syntax near "INNER""..Help Me figure this out..

Private Sub Button1_Click(Byval.....
Dim command as new SqlCommand("Delete From Students Inner Join Classes ON Students.StudentID=Classes.StudentID Where Students.StudentID='" & Registered.CurrentRow.Cells(1).Value & "'",connection)
Jason
  • 11
  • 3
  • Your sql syntax is wrong, see this https://stackoverflow.com/questions/16481379/how-to-delete-using-inner-join-with-sql-server – Tewr Jul 31 '17 at 06:56
  • i tried that link..but couldn't find a solution...i mean none of those work – Jason Jul 31 '17 at 07:00
  • im trying to delete from two tables and also from two DataGridViews – Jason Jul 31 '17 at 07:02
  • Improve your question by providing more info. The less effort you put in your question, the less effort you will get in a response. Which tables are you trying to delete from? Are you using data binding for your data grid views? provide the code that binds data to the datagrid view. Try to provide a [mcve] – Tewr Jul 31 '17 at 07:06
  • That "INNER..." and remaining exception makes sense here since what if there are other dependent tables on either Students/Classes that we don't know? Post relevant details for quick understanding of problem as @Tewr already suggested. – Siva Gopal Jul 31 '17 at 07:51
  • This is the code – Jason Jul 31 '17 at 14:47
  • Private Sub Button1_Click(Byval..... Dim command as new SqlCommand("Delete From Students Inner Join Classes ON Students.StudentID=Classes.StudentID Where Students.StudentID='" & Registered.CurrentRow.Cells(1).Value & "'",connection) – Jason Jul 31 '17 at 14:48
  • If Registered.SelectedRows.Count > 0 Then Registered.Rows.Remove(Registered.CurrentRow) End If connection.Open() delcommand.ExecuteNonQuery() connection.Close() If Registered.SelectedRows.Count > 0 Then Registered.Rows.Remove(Registered.CurrentRow) End If connection.Open() delcommand.ExecuteNonQuery() connection.Close() – Jason Jul 31 '17 at 14:49
  • Sorry for not-spacing – Jason Jul 31 '17 at 14:52

0 Answers0