Please I need help for my thesis. I'm creating a Scheduling for enrollment system. I'm using the Table "classsubjects" for my Testing.
this is my sample code.
Try
con.Open()
cmd.Connection = con
cmd.CommandType = CommandType.Text
cmd.CommandText = String.Format("SELECT * " & _
"FROM classsubjects " & _
"WHERE subject_code='{0}' " & _
"AND subject_name='{1}' " & _
"AND year_level='{2}' ", subjcode.Text, subjname.Text, subjyearlevel.Text)
dr = cmd.ExecuteReader
If dr.HasRows Then
'MsgBox("Conflict Found, please check !", MsgBoxStyle.Critical)
DataGridView1.Rows.Add("subject_ID,subject_code,subject_name,year_level", subjID.Text, subjcode.Text, subjname.Text, subjyearlevel.Text) '
con.Close()
Else
con.Close()
con.Open()
cmd.Connection = con
cmd.CommandType = CommandType.Text
cmd.CommandText = "INSERT into classsubjects(subject_ID, subject_code, subject_name, year_level)VALUES('" + subjID.Text + "','" + subjcode.Text + "','" + subjname.Text + "','" + subjyearlevel.Text + "')"
cmd.ExecuteNonQuery()
MsgBox("Successfully Saved")
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
con.Close()
End Try