Your code is not correctly ordered. You use the SqlCommand before its initialization and of course this results in the mentioned error
dbSource = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\HMS.mdf;Integrated Security=True;User Instance=True"
con = New SqlConnection(dbSource)
con.Open()
Dim sql As String = "INSERT INTO [User] ([Staff_ID], [Staff_Role], [Staff_Name], [Username], [Password]) VALUES (@StaffID, @Role, @StaffName, @Username, @Password) "
cmd = New SqlCommand(sql)
cmd.Connection = con
cmd.Parameters.AddWithValue("@StaffID", txtStaffID.Text)
cmd.Parameters.AddWithValue("@Role", cboRole.Text)
cmd.Parameters.AddWithValue("@StaffName", txtStaffName.Text)
cmd.Parameters.AddWithValue("@Username", txtUsername.Text)
cmd.Parameters.AddWithValue("@Password", txtPassword.Text)
cmd.ExecuteNonQuery()
MessageBox.Show("Successfully saved", "Record", MessageBoxButtons.OK, MessageBoxIcon.Information)
con.Close()
Moved the initialization of the SqlCommand before its first usage and moved the ExecuteNonQuery as the last instruction